MIRA
Classes | Public Types | Public Member Functions | List of all members
XMLDom Class Reference

A STL conform wrapper for libxml2 to read XML files as DOM. More...

#include <xml/XMLDom.h>

Inheritance diagram for XMLDom:
Inheritance graph
[legend]

Classes

class  attribute_iterator
 Iterator for iterating over attributes. More...
 
class  const_attribute_iterator
 Const iterator for iterating over attributes. More...
 
class  const_data_iterator
 Const iterator for iterating over data nodes. More...
 
class  const_sibling_iterator
 Const sibling_iterator for iterating over xml nodes that have the same parent (siblings) More...
 
class  data_iterator
 Iterator for iterating over data nodes. More...
 
class  iterator_base
 Base iterator for iterating over xml nodes with the same parent (siblings) More...
 
struct  NameSpace
 Namespace information of a node. More...
 
class  sibling_iterator
 Iterator for iterating over xml nodes that have the same parent (sibligs) More...
 

Public Types

typedef sibling_iterator iterator
 typedefs for backward compatibility More...
 
typedef const_sibling_iterator const_iterator
 
Public types.
typedef std::pair< std::string, std::string > Attribute
 An XML attribute. More...
 

Public Member Functions

void clear ()
 Clears the whole content of this XMLDom document, i.e. More...
 
std::string uri () const
 Get the URL of the document (i.e. More...
 
void setUri (const std::string &uri)
 Set the URL of the document (i.e. More...
 
std::string encoding () const
 Get the initial encoding of the document. More...
 
Constructor and destructor.
 XMLDom (const std::string &rootNodeName="root")
 Constructor for creating a new empty document. More...
 
 ~XMLDom ()
 Destructor. More...
 
 XMLDom (XMLDom &&other) noexcept
 Move constructor. More...
 
XMLDomoperator= (XMLDom &&other) noexcept
 Move assignment operator. More...
 
I/O operations.
void loadFromString (const std::string &buffer)
 Load and parse an XML document from memory. More...
 
void loadFromFile (const Path &filename, bool resolve=true)
 Load and parse an XML document from a file. More...
 
void saveToFile (const Path &filename, const std::string &encoding="UTF-8", bool resolve=true) const
 Save the XML document to a file. More...
 
void saveToFile (const Path &filename, bool resolve) const
 Save the XML document to a file, using encoding UTF-8. More...
 
std::string saveToString (const std::string &encoding="UTF-8") const
 Save the XML document to a string. More...
 
Iterators.
const_sibling_iterator croot () const
 Return a const sibling_iterator to the root node of the XML document. More...
 
const_sibling_iterator root () const
 Return a const sibling_iterator to the root node of the XML document. More...
 
sibling_iterator root ()
 Return a sibling_iterator to the root node of the XML document. More...
 

Iterator types.

typedef const_data_iterator< COMMENT_NODE > const_comment_iterator
 STL-conform typedefs. More...
 
typedef const_data_iterator< TEXT_NODE > const_content_iterator
 The const iterator for content. More...
 
typedef data_iterator< COMMENT_NODE > comment_iterator
 The iterator for comments. More...
 
typedef data_iterator< TEXT_NODE > content_iterator
 The iterator for content. More...
 
class MIRA_BASE_EXPORT sibling_iterator
 
class MIRA_BASE_EXPORT const_sibling_iterator
 

Detailed Description

A STL conform wrapper for libxml2 to read XML files as DOM.

Member Typedef Documentation

◆ Attribute

typedef std::pair<std::string, std::string> Attribute

An XML attribute.

◆ iterator

typedefs for backward compatibility

◆ const_iterator

Constructor & Destructor Documentation

◆ XMLDom() [1/2]

XMLDom ( const std::string &  rootNodeName = "root")

Constructor for creating a new empty document.

The name of the root node can specified as optional parameter. The default name is "root".

◆ ~XMLDom()

~XMLDom ( )

Destructor.

◆ XMLDom() [2/2]

XMLDom ( XMLDom &&  other)
noexcept

Move constructor.

Member Function Documentation

◆ operator=()

XMLDom& operator= ( XMLDom &&  other)
noexcept

Move assignment operator.

◆ clear()

void clear ( )

Clears the whole content of this XMLDom document, i.e.

all nodes are destroyed and the XMLDom object has the same state as after calling it's constructor. Note: All iterators become invalid by calling this method. Accessing the iterators after calling this method will result in undefined behavior.

◆ loadFromString()

void loadFromString ( const std::string &  buffer)

Load and parse an XML document from memory.

Exceptions
XIOif the document could not be loaded.
Parameters
[in]bufferThe buffer.

◆ loadFromFile()

void loadFromFile ( const Path filename,
bool  resolve = true 
)

Load and parse an XML document from a file.

Exceptions
XFileNotFoundif file is not found.
XIOif the file/document could not be loaded.
Parameters
[in]filenameThe file name.
[in]resolveShould the filename be resolved (resolvePath())? Set to false if already resolved.

◆ saveToFile() [1/2]

void saveToFile ( const Path filename,
const std::string &  encoding = "UTF-8",
bool  resolve = true 
) const

Save the XML document to a file.

Exceptions
XInvalidConfigif the document is empty.
XIOif the file could not be saved.
Parameters
[in]filenameThe file name.
[in]encodingThe desired encoding.
[in]resolveShould the filename be resolved (resolvePath())? Set to false if already resolved.

◆ saveToFile() [2/2]

void saveToFile ( const Path filename,
bool  resolve 
) const

Save the XML document to a file, using encoding UTF-8.

Exceptions
XInvalidConfigif the document is empty.
XIOif the file could not be saved.
Parameters
[in]filenameThe file name.
[in]resolveShould the filename be resolved (resolvePath())? Set to false if already resolved.

◆ saveToString()

std::string saveToString ( const std::string &  encoding = "UTF-8") const

Save the XML document to a string.

Exceptions
XInvalidConfigif the document is empty.
XIOif the file could not be saved.
Parameters
[in]encodingThe desired encoding.
Returns
The string containing the xml document

◆ croot()

const_sibling_iterator croot ( ) const

Return a const sibling_iterator to the root node of the XML document.

◆ root() [1/2]

const_sibling_iterator root ( ) const
inline

Return a const sibling_iterator to the root node of the XML document.

◆ root() [2/2]

sibling_iterator root ( )

Return a sibling_iterator to the root node of the XML document.

◆ uri()

std::string uri ( ) const

Get the URL of the document (i.e.

the filename if loaded from file)

Returns
URL of the document

◆ setUri()

void setUri ( const std::string &  uri)

Set the URL of the document (i.e.

the filename if loaded from file)

◆ encoding()

std::string encoding ( ) const

Get the initial encoding of the document.

Returns
Encoding if any.

The documentation for this class was generated from the following file: