zen::Xml
Simple C++ XML Processing
 All Classes Namespaces Functions Variables Pages
Classes | Functions
zen Namespace Reference

The zen::Xml namespace. More...

Classes

class  XmlDoc
 The complete XML document. More...
 
class  XmlElement
 An XML element. More...
 
struct  XmlError
 Exception base class for zen::Xml. More...
 
struct  XmlFileError
 Exception thrown due to failed file I/O. More...
 
class  XmlIn
 Proxy class to conveniently convert XML structure to user data. More...
 
class  XmlOut
 Proxy class to conveniently convert user data into XML structure. More...
 
struct  XmlParsingError
 Exception thrown due to an XML parsing error. More...
 

Functions

template<class String >
XmlDoc load (const String &filename)
 Load XML document from a file. More...
 
template<class String >
void save (const XmlDoc &doc, const String &filename, const std::string &lineBreak="\r\n", const std::string &indent=" ")
 Save XML document to a file. More...
 
template<class T >
bool readStruc (const XmlElement &input, T &value)
 Convert XML element to structured user data. More...
 
template<class T >
void writeStruc (const T &value, XmlElement &output)
 Convert structured user data into an XML element. More...
 
template<class T >
bool readText (const std::string &input, T &value)
 Convert text to user data - used by XML elements and attributes. More...
 
template<class T >
void writeText (const T &value, std::string &output)
 Convert user data into text - used by XML elements and attributes. More...
 
template<class String >
void saveStream (const std::string &stream, const String &filename)
 Save byte stream to a file. More...
 
template<class String >
std::string loadStream (const String &filename)
 Load byte stream from a file. More...
 
std::string serialize (const XmlDoc &doc, const std::string &lineBreak="\r\n", const std::string &indent=" ")
 Save XML document as a byte stream. More...
 
XmlDoc parse (const std::string &stream)
 Load XML document from a byte stream. More...
 

Detailed Description

The zen::Xml namespace.

Function Documentation

template<class String >
XmlDoc zen::load ( const String &  filename)

Load XML document from a file.

Convenience function that does nothing more than calling loadStream() and parse().

Template Parameters
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters
filenameInput file name
Returns
The loaded XML document
Exceptions
XmlFileError
XmlParsingError
template<class String >
std::string zen::loadStream ( const String &  filename)

Load byte stream from a file.

Template Parameters
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters
filenameInput file name
Returns
Output byte stream
Exceptions
XmlFileError
XmlDoc zen::parse ( const std::string &  stream)

Load XML document from a byte stream.

Parameters
streamInput byte stream
Returns
Output XML document
Exceptions
XmlParsingError
template<class T >
bool zen::readStruc ( const XmlElement &  input,
T &  value 
)

Convert XML element to structured user data.

Parameters
inputThe input XML element.
valueConversion target value.
Returns
"true" if value was read successfully.
template<class T >
bool zen::readText ( const std::string &  input,
T &  value 
)

Convert text to user data - used by XML elements and attributes.

Parameters
inputInput text.
valueConversion target value.
Returns
"true" if value was read successfully.
template<class String >
void zen::save ( const XmlDoc &  doc,
const String &  filename,
const std::string &  lineBreak = "\r\n",
const std::string &  indent = "    " 
)

Save XML document to a file.

Convenience function that does nothing more than calling serialize() and saveStream().

Template Parameters
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters
docThe XML document to save
filenameOutput file name
lineBreakLine break, default: carriage return + new line
indentIndentation, default: four space characters
Exceptions
XmlFileError
template<class String >
void zen::saveStream ( const std::string &  stream,
const String &  filename 
)

Save byte stream to a file.

Template Parameters
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters
streamInput byte stream
filenameOutput file name
Exceptions
XmlFileError
std::string zen::serialize ( const XmlDoc &  doc,
const std::string &  lineBreak = "\r\n",
const std::string &  indent = "    " 
)

Save XML document as a byte stream.

Parameters
docInput XML document
lineBreakLine break, default: carriage return + new line
indentIndentation, default: four space characters
Returns
Output byte stream
template<class T >
void zen::writeStruc ( const T &  value,
XmlElement &  output 
)

Convert structured user data into an XML element.

Parameters
valueThe value to be converted.
outputThe output XML element.
template<class T >
void zen::writeText ( const T &  value,
std::string &  output 
)

Convert user data into text - used by XML elements and attributes.

Parameters
valueThe value to be converted.
outputOutput text.