XML writer
-
class xml_writer
This class lets you produce XML contents from scratch. It writes its content to any object supporting the std::ostream interface.
Public Functions
-
xml_writer(const xml_writer&) = delete
-
xml_writer &operator=(const xml_writer&) = delete
-
xml_writer(xmlns_repository &ns_repo, std::ostream &os)
-
xml_writer(xml_writer &&other)
-
xml_writer &operator=(xml_writer &&other)
-
~xml_writer()
Destructor. Any remaining element(s) on the stack will get popped when the destructor is called.
-
scope 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:
name – name of the new element.
- Returns:
scope object which automatically pops the element when it goes out of scope.
-
void push_element(const xml_name_t &name)
Push a new element to the stack, and write an opening element to the output stream.
- Parameters:
name – name of the element.
-
xmlns_id_t add_namespace(std::string_view alias, std::string_view value)
Add a namespace definition for the next element to be pushed.
- Parameters:
alias – alias for the namespace.
value – value of the namespace definition.
- Returns:
ID for the namespace being added.
-
void add_attribute(const xml_name_t &name, std::string_view value)
Add a new attribute for the next element to be pushed.
- Parameters:
name – name of the attribute to be added.
value – value of the attribute to be added.
-
void add_content(std::string_view content)
Add a content to the current element on the stack. The content will be properly encoded.
- Parameters:
content – content to be added to the current element.
-
xml_name_t 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.
-
class scope
-
xml_writer(const xml_writer&) = delete