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

The zen::Xml namespace. More...

Classes

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

Functions

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

Detailed Description

The zen::Xml namespace.


Function Documentation

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

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
docThe XML document to load
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
void zen::parse ( const std::string &  stream,
XmlDoc &  doc 
)

Load XML document from a byte stream.

Parameters:
streamInput byte stream
docOutput 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.