ROOT  6.07/01
Reference Guide
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
xmlnewfile.C
Go to the documentation of this file.
1 // Example to create a new xml file with the TXMLEngine class
2 //Author: Sergey Linev
3 
4 #include "TXMLEngine.h"
5 
6 void xmlnewfile(const char* filename = "example.xml")
7 {
8  // First create engine
9  TXMLEngine* xml = new TXMLEngine;
10 
11  // Create main node of document tree
12  XMLNodePointer_t mainnode = xml->NewChild(0, 0, "main");
13 
14  // Simple child node with content inside
15  xml->NewChild(mainnode, 0, "child1", "Content of child1 node");
16 
17  // Other child node with attributes
18  XMLNodePointer_t child2 = xml->NewChild(mainnode, 0, "child2");
19  xml->NewAttr(child2, 0, "attr1","value1");
20  xml->NewAttr(child2, 0, "attr2","value2");
21 
22  // Child node with subnodes
23  XMLNodePointer_t child3 = xml->NewChild(mainnode, 0, "child3");
24  xml->NewChild(child3, 0, "subchild1", "subchild1 content");
25  xml->NewChild(child3, 0, "subchild2", "subchild2 content");
26  xml->NewChild(child3, 0, "subchild3", "subchild3 content");
27 
28  // Child node with subnodes and namespace
29  XMLNodePointer_t child4 = xml->NewChild(mainnode, 0, "child4");
30  XMLNsPointer_t ns4 = xml->NewNS(child4, "http://wesite/webpage");
31  xml->NewChild(child4, ns4, "subchild1", "subchild1 content");
32  xml->NewChild(child4, ns4, "subchild2", "subchild2 content");
33  xml->NewChild(child4, ns4, "subchild3", "subchild3 content");
34 
35  // now create doccumnt and assign main node of document
36  XMLDocPointer_t xmldoc = xml->NewDoc();
37  xml->DocSetRootElement(xmldoc, mainnode);
38 
39  // Save document to file
40  xml->SaveDoc(xmldoc, filename);
41 
42  // Release memory before exit
43  xml->FreeDoc(xmldoc);
44  delete xml;
45 }
void xmlnewfile(const char *filename="example.xml")
Definition: xmlnewfile.C:6
XMLDocPointer_t NewDoc(const char *version="1.0")
creates new xml document with provided version
static const char * filename()
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
void * XMLDocPointer_t
Definition: TXMLEngine.h:22
void DocSetRootElement(XMLDocPointer_t xmldoc, XMLNodePointer_t xmlnode)
set main (root) node for document
XMLNsPointer_t NewNS(XMLNodePointer_t xmlnode, const char *reference, const char *name=0)
create namespace attribute for xmlnode.
Definition: TXMLEngine.cxx:641
void SaveDoc(XMLDocPointer_t xmldoc, const char *filename, Int_t layout=1)
store document content to file if layout<=0, no any spaces or newlines will be placed between xmlnode...
void * XMLNodePointer_t
Definition: TXMLEngine.h:19
XMLAttrPointer_t NewAttr(XMLNodePointer_t xmlnode, XMLNsPointer_t, const char *name, const char *value)
creates new attribute for xmlnode, namespaces are not supported for attributes
Definition: TXMLEngine.cxx:488
void * XMLNsPointer_t
Definition: TXMLEngine.h:20
XMLNodePointer_t NewChild(XMLNodePointer_t parent, XMLNsPointer_t ns, const char *name, const char *content=0)
create new child element for parent node
Definition: TXMLEngine.cxx:614