zen::Xml: zen::XmlOut Class Reference

| zen::Xml Simple C++ XML Processing

- Main Page
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

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...
XmlElement & | ref ()
| 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"]( 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::XmlDoc doc;
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

  String | Arbitrary string-like type: e.g. std::string, wchar_t*, char[], wchar_t, wxString, MyStringClass, ...
  T | String-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

  T | User 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

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

Parameters

  name | The name of the child element