Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Version 2 (modified by landauf, 3 years ago) (diff)

fixed links

This is an archived page!
This page is very old and the content is not up to date.
Not everything (if any) which is written here will be in the final game!

XML-Writer

Under construction

Library

Suggestion: Simple C++ class for XML writing from Oboltus.

Using this class is very very simple, it's all based on the stream operator <<. Here's an example:

ofstream f("sample.xml");
XmlStream xml(f);

xml << prolog() // write XML file declaration
  << tag("sample-tag") // root tag

    << tag("some-tag") // child tag
      << attr("int-attribute") << 123
      << attr("double-attribute") << 456.789
      << chardata() << "This is the text"
    << endtag() // close current tag

    << tag("empty-self-closed-tag") // sibling of <some-tag>
    << endtag()

    << tag() << "computed-name-tag"
      << attr("text-attr") << "a bit of text"
    << endtag()

    << tag("deep-tag") // deep enclosing
      << tag("sub-tag-2")
        << tag("sub-tag-3")
    << endtag("deep-tag"); // close all tags up to specified

// you don't worry about closing all open tags!

Result:

<?xml version="1.0"?>
<sample-tag>
<some-tag int-attribute="123" double-attribute="456.789">This is the text
</some-tag>
<empty-self-closed-tag/>
<computed-name-tag text-attr="a bit of text"/>
<deep-tag>
<sub-tag-2>
<sub-tag-3/>
</sub-tag-2>
</deep-tag>
</sample-tag>

The layout isn't optimal yet, but I'll try to fix that.

Misc

See XML-Loader for an XML-Reader description