Xmlnewfile

Example to create a new xml file with the TXMLEngine class

Author: Sergey Linev
This notebook tutorial was automatically generated with ROOTBOOK-izer from the macro found in the ROOT repository on Saturday, September 18, 2021 at 10:02 AM.

In [1]:
%%cpp -d
#include "TXMLEngine.h"

Arguments are defined.

In [2]:
const char* filename = "example.xml";

First create engine

In [3]:
TXMLEngine xml;

Create main node of document tree

In [4]:
XMLNodePointer_t mainnode = xml.NewChild(0, 0, "main");

Simple child node with content inside

In [5]:
xml.NewChild(mainnode, 0, "child1", "Content of child1 node");

Other child node with attributes

In [6]:
XMLNodePointer_t child2 = xml.NewChild(mainnode, 0, "child2");
xml.NewAttr(child2, 0, "attr1","value1");
xml.NewAttr(child2, 0, "attr2","value2");

Child node with subnodes

In [7]:
XMLNodePointer_t child3 = xml.NewChild(mainnode, 0, "child3");
xml.NewChild(child3, 0, "subchild1", "subchild1 content");
xml.NewChild(child3, 0, "subchild2", "subchild2 content");
xml.NewChild(child3, 0, "subchild3", "subchild3 content");

Child node with subnodes and namespace

In [8]:
XMLNodePointer_t child4 = xml.NewChild(mainnode, 0, "child4");
XMLNsPointer_t ns4 = xml.NewNS(child4, "http://website/webpage");
xml.NewChild(child4, ns4, "subchild1", "subchild1 content");
xml.NewChild(child4, ns4, "subchild2", "subchild2 content");
xml.NewChild(child4, ns4, "subchild3", "subchild3 content");

Now create document and assign main node of document

In [9]:
XMLDocPointer_t xmldoc = xml.NewDoc();
xml.DocSetRootElement(xmldoc, mainnode);

Save document to file

In [10]:
xml.SaveDoc(xmldoc, filename);

Release memory before exit

In [11]:
xml.FreeDoc(xmldoc);