zen::Xml: zen Namespace Reference

| zen::Xml Simple C++ XML Processing

- Main Page
- Namespaces
- Classes

- Namespace List
- Namespace Members

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

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

Parameters

  filename | Input 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

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

Parameters

  filename | Input file name

Returns
  Output byte stream

Exceptions

  XmlFileError |

XmlDoc zen::parse | ( | const std::string & | stream | ) |

Load XML document from a byte stream.

Parameters

  stream | Input 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

  input | The input XML element.
  value | Conversion 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

  input | Input text.
  value | Conversion 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

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

Parameters

  doc | The XML document to save
  filename | Output file name
  lineBreak | Line break, default: carriage return + new line
  indent | Indentation, 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

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...

Parameters

  stream | Input byte stream
  filename | Output 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

  doc | Input XML document
  lineBreak | Line break, default: carriage return + new line
  indent | Indentation, 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

  value | The value to be converted.
  output | The 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

  value | The value to be converted.
  output | Output text.