zen::Xml
Simple C++ XML Processing
 All Classes Namespaces Functions Variables Pages
Public Member Functions | List of all members
zen::XmlOut Class Reference

Proxy class to conveniently convert user data into XML structure. More...

#include <bind.h>

Public Member Functions

 XmlOut (XmlDoc &doc)
 Construct an output proxy for an XML document. More...
 
 XmlOut (XmlElement &element)
 Construct an output proxy for a single XML element. More...
 
template<class String >
XmlOut operator[] (const String &name) const
 Retrieve a handle to an XML child element for writing. More...
 
template<class T >
void operator() (const T &value)
 Write user data to the underlying XML element. More...
 
template<class String , class T >
void attribute (const String &name, const T &value)
 Write user data to an XML attribute. More...
 
XmlElementref ()
 Return a reference to the underlying Xml element.
 

Detailed Description

Proxy class to conveniently convert user data into XML structure.

Constructor & Destructor Documentation

zen::XmlOut::XmlOut ( XmlDoc doc)

Construct an output proxy for an XML document.

zen::XmlOut out(doc);
out["elem1"]( 1); //
out["elem2"]( 2); //write data into XML elements
out["elem3"](-3); //
save(doc, "out.xml"); //throw XmlFileError

Output:

<?xml version="1.0" encoding="UTF-8"?>
<Root>
    <elem1>1</elem1>
    <elem2>2</elem2>
    <elem3>-3</elem3>
</Root>
zen::XmlOut::XmlOut ( XmlElement element)

Construct an output proxy for a single XML element.

See Also
XmlOut(XmlDoc& doc)

Member Function Documentation

template<class String , class T >
void zen::XmlOut::attribute ( const String &  name,
const T &  value 
)

Write user data to an XML attribute.

This conversion requires a specialization of zen::writeText() for type T.

zen::XmlOut out(doc);
out["elem"].attribute("attr1", 1); //
out["elem"].attribute("attr2", 2); //write data into XML attributes
out["elem"].attribute("attr3", -3); //
save(doc, "out.xml"); //throw XmlFileError

Output:

  <?xml version="1.0" encoding="UTF-8"?>
  <Root>
      <elem attr1="1" attr2="2" attr3="-3"/>
  </Root>
Template Parameters
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
TString-convertible user data type: e.g. any string-like type, all built-in arithmetic numbers
See Also
XmlElement::setAttribute()
template<class T >
void zen::XmlOut::operator() ( const T &  value)

Write user data to the underlying XML element.

This conversion requires a specialization of zen::writeText() or zen::writeStruc() for type T.

Template Parameters
TUser type that is converted into an XML element value.
template<class String >
XmlOut zen::XmlOut::operator[] ( const String &  name) const

Retrieve a handle to an XML child element for writing.

The child element will be created if it is not yet existing.

Template Parameters
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
Parameters
nameThe name of the child element