32 #include <Base/Common/XMLIO.hh>
37 int main (
int ,
char** )
45 xmlNodePtr currentNode2;
46 xmlNodePtr currentNode3;
52 rootNode = myXML.
create(
"XMLTest");
57 myXML.
addAttribute(currentNode2,
"Attrib1", std::string(
"1234") );
58 myXML.
addAttribute(currentNode2,
"Attribute2", std::string(
"4321.1234") );
59 myXML.
addAttribute(currentNode2,
"NextAttribute", std::string(
"Content of attribute 3") );
61 std::string(
"The content of a node is written between the opening and closing tag.") );
63 currentNode3 = myXML.
addChildNode(currentNode2,
"ChildOfChild1");
64 myXML.
addAttribute(currentNode3,
"AttributeOfChildOfChild1", std::string(
"FULL") );
65 myXML.
addAttribute(currentNode3,
"AttributeWithUmlaute", std::string(
"özil") );
69 myXML.
addContent(currentNode3,
"myContent wtith umlaute. Schöner Mist");
75 myXML.
addAttribute(currentNode2,
"my Attribute", std::string(
"will produce an error") );
80 currentNode2 = myXML.
addChildNode(rootNode,
"ThisIsChild3");
81 myXML.
addAttribute(currentNode2,
"Roundness", std::string(
"Child 3 is very round") );
82 myXML.
addContent(currentNode2,
"Just some content");
85 if (myXML.
write(
"test.xml") <0) exit(1);
94 rootNode = myXML.
read(
"test.xml");
95 if (rootNode == NULL) {
96 cout <<
"PARSING ERROR! Exiting XML-sample program...." << endl;
103 while (currentNode2!=NULL) {
105 cout << endl << myXML.
getNodeName(currentNode2) << endl;
109 while (currAttr!=NULL) {
118 while (currentNode3!=NULL) {
119 cout << endl <<
" Child: " << myXML.
getNodeName(currentNode3) << endl;
122 cout <<
" Child Cont.: '" << content << endl;
126 while (currAttr!=NULL) {
138 cout << endl << endl <<
"Distinct Access:" << endl;
140 currentNode2 = myXML.
getChild(rootNode,
"ThisIsChild3");
141 if (currentNode2!=NULL) {
142 cout <<
"'Roundness' of 'ThisIsChild3': " <<
146 currentNode2 = myXML.
getChild(rootNode,
"Child1");
147 if (currentNode2!=NULL) {
148 cout <<
"'Attrib1' of 'Child1': " <<
150 cout <<
"'Attribute2' of 'Child1': " <<
void addAttribute(const xmlNodePtr Node, const std::string &AttributeName, bool AttributeValue)
Add an attribute to a node.
std::string getAttributeName(const xmlAttrPtr Attribute) const
Get the name of a given Attribute.
xmlNodePtr getNextChild()
Get the next child of the parent specified in the last getFirstChild() call, the class remembers the ...
int write(const std::string &Filename, bool AutoAddCompressionSuffix=true) const
Write the whole tree that was constructed in memory to disk.
xmlNodePtr read(const std::string &Filename)
Read and parse an XML file from disk, DtD validation is not yet implemented.
xmlNodePtr getChild(const xmlNodePtr ParentNode, const std::string &ChildName)
Get a child of a Parent node by specifying the childs name, NULL is returned if the ParentNode has no...
xmlNodePtr create(const std::string &RootNodeName)
Create the base of a new XML-Tree in memory, already with a one and only root node.
xmlAttrPtr getFirstAttribute(const xmlNodePtr Node)
Get the first attribute of a given parent, or NULL for no attributes.
std::string getAttributeValueString(const xmlAttrPtr Attribute) const
int getAttributeValueInt(const xmlAttrPtr Attribute) const
void addContent(const xmlNodePtr Node, const std::string &Content)
Add content to a node.
Wrapper class for reading and writing XML files based on the XML library libxml2. ...
xmlNodePtr addChildNode(const xmlNodePtr ParentNode, const std::string &NewNodeName)
Add a child node to an incoming node with the given name.
xmlNodePtr getFirstChild(const xmlNodePtr ParentNode)
Get the first child of a given parent, or NULL for no childs.
xmlAttrPtr getNextAttribute()
Get the next attribute of the parent specified in the last getFirstAttribute() call, the class remembers the last returned attribute.
double getAttributeValueDouble(const xmlAttrPtr Attribute) const
std::string getNodeName(const xmlNodePtr Node) const
Get the name of a given Node.
std::string getNodeContentString(const xmlNodePtr Node) const
Get the content of a given Node.