libcommonc++  0.7
XMLDocument Class Reference

An object representing an XML document. More...

#include <XMLDocument.h++>

Public Member Functions

 XMLDocument ()
 Construct a new XMLDocument. More...
 
 ~XMLDocument ()
 Destructor. More...
 
XMLElementgetRoot ()
 Get the root element of the document. More...
 
const XMLElementgetRoot () const
 Get the root element of the document. More...
 
XMLElementsetRoot (const String &name)
 Set the root element of the document. More...
 
XMLElementfind (const String &path)
 Find an XML element via a path. More...
 
const XMLElementfind (const String &path) const
 Find an XML element via a path. More...
 
void read (std::istream &stream)
 Read and parse the XML document from a stream. More...
 
void read (const String &str)
 Read and parse the XML document from a String. More...
 
void write (std::ostream &stream, uint_t tabWidth=2) const
 Format and write the XML document to a stream. More...
 
void write (String &str, uint_t tabWidth=2) const
 Format and write the XML document to a String. More...
 
bool isEmpty () const
 Test if the document is empty. More...
 
bool operator! () const
 Test if the document is empty. More...
 

Detailed Description

An object representing an XML document.

Author
Mark Lindner

Constructor & Destructor Documentation

◆ XMLDocument()

Construct a new XMLDocument.

◆ ~XMLDocument()

Destructor.

Member Function Documentation

◆ find() [1/2]

XMLElement & find ( const String path)

Find an XML element via a path.

Parameters
pathThe path, a dot- or slash-separated list of element names beginning with the root element.
Returns
The first matching element, if found, otherwise XMLElement::null.
Exceptions
InvalidArgumentExceptionIf the path contains invalid element names.

◆ find() [2/2]

const XMLElement & find ( const String path) const

Find an XML element via a path.

Parameters
pathThe path, a dot- or slash-separated list of element names beginning with the root element.
Returns
The first matching element, if found, otherwise XMLElement::null.
Exceptions
InvalidArgumentExceptionIf the path contains invalid element names.

◆ getRoot() [1/2]

XMLElement & getRoot ( )

Get the root element of the document.

Returns
A reference to the root element, or XMLElement::null if the document is empty.

◆ getRoot() [2/2]

const XMLElement & getRoot ( ) const

Get the root element of the document.

Returns
A reference to the root element, or XMLElement::null if the document is empty.

◆ isEmpty()

bool isEmpty ( ) const
inline

Test if the document is empty.

Returns
true if the document is empty, false otherwise.

◆ operator!()

bool operator! ( ) const
inline

Test if the document is empty.

Returns
true if the document is empty, false otherwise.

◆ read() [1/2]

void read ( std::istream &  stream)

Read and parse the XML document from a stream.

Parameters
streamThe stream to read from.
Exceptions
ParseExceptionIf a parse error occurs.
IOExceptionIf an I/O error occurs.

◆ read() [2/2]

void read ( const String str)

Read and parse the XML document from a String.

Parameters
strThe String to read from.
Exceptions
ParseExceptionIf a parse error occurs.

◆ setRoot()

XMLElement & setRoot ( const String name)

Set the root element of the document.

The previous content of the document is deleted.

Parameters
nameThe name for the new element.
Returns
A reference to the new element.
Exceptions
InvalidArgumentExceptionIf the name is invalid.

◆ write() [1/2]

void write ( std::ostream &  stream,
uint_t  tabWidth = 2 
) const

Format and write the XML document to a stream.

Parameters
streamThe stream to write to.
tabWidthThe tab width for indentation; a value of 0 disables pretty-printing.
Exceptions
IOExceptionIf an I/O error occurs.

◆ write() [2/2]

void write ( String str,
uint_t  tabWidth = 2 
) const

Format and write the XML document to a String.

Parameters
strThe String to write to.
tabWidthThe tab width for indentation; a value of 0 disables pretty-printing.

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