Orcus
Loading...
Searching...
No Matches
orcus::xml_writer Class Reference

#include <xml_writer.hpp>

Classes

class  scope

Public Member Functions

 xml_writer (const xml_writer &)=delete
xml_writeroperator= (const xml_writer &)=delete
 xml_writer (xmlns_repository &ns_repo, std::ostream &os)
 xml_writer (xml_writer &&other)
xml_writeroperator= (xml_writer &&other)
 ~xml_writer ()
scope push_element_scope (const xml_name_t &name)
void push_element (const xml_name_t &name)
xmlns_id_t add_namespace (std::string_view alias, std::string_view value)
void add_attribute (const xml_name_t &name, std::string_view value)
void add_content (std::string_view content)
xml_name_t pop_element ()

Detailed Description

This class lets you produce XML contents from scratch. It writes its content to any object supporting the std::ostream interface.

Constructor & Destructor Documentation

◆ ~xml_writer()

orcus::xml_writer::~xml_writer ( )

Destructor. Any remaining element(s) on the stack will get popped when the destructor is called.

Member Function Documentation

◆ add_attribute()

void orcus::xml_writer::add_attribute ( const xml_name_t & name,
std::string_view value )

Add a new attribute for the next element to be pushed.

Parameters
namename of the attribute to be added.
valuevalue of the attribute to be added.

◆ add_content()

void orcus::xml_writer::add_content ( std::string_view content)

Add a content to the current element on the stack. The content will be properly encoded.

Parameters
contentcontent to be added to the current element.

◆ add_namespace()

xmlns_id_t orcus::xml_writer::add_namespace ( std::string_view alias,
std::string_view value )

Add a namespace definition for the next element to be pushed.

Parameters
aliasalias for the namespace.
valuevalue of the namespace definition.
Returns
ID for the namespace being added.

◆ pop_element()

xml_name_t orcus::xml_writer::pop_element ( )

Pop the current element from the stack, and write a closing element to the output stream.

Returns
the name of the element being popped.

◆ push_element()

void orcus::xml_writer::push_element ( const xml_name_t & name)

Push a new element to the stack, and write an opening element to the output stream.

Parameters
namename of the element.

◆ push_element_scope()

scope orcus::xml_writer::push_element_scope ( const xml_name_t & name)

Push a new element to the stack, and write an opening element to the output stream. It differs from the push_element method in that the new element will be automatically popped when the returned object goes out of scope.

Parameters
namename of the new element.
Returns
scope object which automatically pops the element when it goes out of scope.