zenXML
Straightforward C++ XML Processing
Public Member Functions
zen::XmlOut Class Reference

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

#include <zenxml_bind.h>

List of all members.

Public Member Functions

 XmlOut (XmlDoc &doc)
 Construct an output proxy for an XML document.
 XmlOut (XmlElement &element)
 Construct an output proxy for a single XML element.
template<class String >
XmlOut operator[] (const String &name) const
 Retrieve a handle to an XML child element for writing.
template<class T >
void operator() (const T &value)
 Write user data to the underlying XML element.
template<class String , class T >
void attribute (const String &name, const T &value)
 Write user data to an XML attribute.
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::XmlDoc doc;

        zen::XmlOut out(doc);
        out["elem1"](value1); //
        out["elem2"](value2); //write data of variables "value1", "value2", "value3" into XML elements
        out["elem3"](value3); //

        save(doc, "out.xml"); //throw XmlFileError

Output:

      <?xml version="1.0" encoding="UTF-8"?>
      <Root>
          <elem1>1</elem1>
          <elem2>2.000000</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::XmlDoc doc;

        zen::XmlOut out(doc);
        out["elem"].attribute("attr1", value1); //
        out["elem"].attribute("attr2", value2); //write data of variables "value1", "value2", "value3" into XML attributes
        out["elem"].attribute("attr3", value3); //

        save(doc, "out.xml"); //throw XmlFileError

Output:

      <?xml version="1.0" encoding="UTF-8"?>
      <Root>
          <elem attr1="1" attr2="2.000000" attr3="-3"/>
      </Root>
      
Template Parameters:
StringArbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
TUser type that is converted into an XML attribute value.
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::writeValue() 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
 All Classes Namespaces Functions Variables