This module contains classes to write an XML document following a "open on create - close on destroy" idiom. More...
Classes | |
class | CLAM::XmlFragment |
This is the first scoped object you should create for a XML fragment. More... | |
class | CLAM::XmlContent |
An scoped XML writer object inserting plain content to the current XML level. More... | |
class | CLAM::XmlElement |
An scoped XML writer object that opens a new element on construction and closes it on destruction. More... | |
class | CLAM::XmlAttribute |
An scoped XML writer object that inserts on construction an XML atribute to the last open XML element. More... |
This module contains classes to write an XML document following a "open on create - close on destroy" idiom.
That means that by simply creating an element object you are opening a tag and when the element object goes out of scope the element is automatically closed. The C++ stack frame managing rules assure that the XML will be well balanced.
This system only provides writing XML and has no mapping to CLAM data as CLAM::XmlStorage has. See the XmlStorage way .
Two aproaches can be convined to generate XML with scoped objects:
XmlFragment(std::cout); { XmlElement element("Configuration"); { XmlElement element("Parameter"); XmlAttribute attrib("name","SpectralHeight"); XmlContent content(1276.3); } { XmlElement element("Parameter"); XmlAttribute attrib("name","Filename"); XmlContent content("Voice.wav"); } }
The first scoped object must be a top level one like XmlFragment (XmlDocument will be available soon). That element defines the target ostream where the XML will be written.
// Wrong code XmlElement("MyTag"); { XmlElement("Child"); XmlContent("hello"); }
<MyTag /><Child />hello
instead the probably intended: <MyTag><Child>hello</Child></MyTag>
the correct code should be: XmlElement element("MyTag"); { XmlElement element("Child"); XmlContent content("hello"); }