Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
xmlreadfile.C
Go to the documentation of this file.
1/// \file
2/// \ingroup tutorial_xml
3///
4/// Example to read and parse any xml file, supported by TXMLEngine class
5/// The input file, produced by xmlnewfile.C macro is used
6/// If you need full xml syntax support, use TXMLParser instead
7///
8/// \macro_code
9///
10/// \author Sergey Linev
11
12#include "TXMLEngine.h"
13#include <cstdio>
14
15void DisplayNode(TXMLEngine &xml, XMLNodePointer_t node, Int_t level)
16{
17 // this function display all accessible information about xml node and its children
18
19 printf("%*c node: %s\n", level, ' ', xml.GetNodeName(node));
20
21 // display namespace
22 XMLNsPointer_t ns = xml.GetNS(node);
23 if (ns != nullptr)
24 printf("%*c namespace: %s refer: %s\n", level + 2, ' ', xml.GetNSName(ns), xml.GetNSReference(ns));
25
26 // display attributes
28 while (attr != nullptr) {
29 printf("%*c attr: %s value: %s\n", level + 2, ' ', xml.GetAttrName(attr), xml.GetAttrValue(attr));
30 attr = xml.GetNextAttr(attr);
31 }
32
33 // display content (if exists)
34 const char *content = xml.GetNodeContent(node);
35 if (content != nullptr)
36 printf("%*c cont: %s\n", level + 2, ' ', content);
37
38 // display all child nodes
40 while (child != nullptr) {
41 DisplayNode(xml, child, level + 2);
42 child = xml.GetNext(child);
43 }
44}
45
46void xmlreadfile(const char* filename = "example.xml")
47{
48 // First create engine
49 TXMLEngine xml;
50
51 // Now try to parse xml file
52 // Only file with restricted xml syntax are supported
54 if (!xmldoc) return;
55
56 // take access to main node
57 XMLNodePointer_t mainnode = xml.DocGetRootElement(xmldoc);
58
59 // display recursively all nodes and subnodes
60 DisplayNode(xml, mainnode, 1);
61
62 // Release memory before exit
63 xml.FreeDoc(xmldoc);
64}
int Int_t
Definition RtypesCore.h:45
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t TString Int_t GCValues_t GetPrimarySelectionOwner GetDisplay GetScreen GetColormap GetNativeEvent const char const char dpyName wid window const char font_name cursor keysym reg const char only_if_exist regb h Point_t winding char text const char depth char const char Int_t count const char ColorStruct_t color const char filename
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t Float_t Float_t Float_t Int_t Int_t UInt_t UInt_t Rectangle_t Int_t Int_t Window_t child
Option_t Option_t TPoint TPoint const char GetTextMagnitude GetFillStyle GetLineColor GetLineWidth GetMarkerStyle GetTextAlign GetTextColor GetTextSize void char Point_t Rectangle_t WindowAttributes_t attr
void * XMLNodePointer_t
Definition TXMLEngine.h:17
void * XMLNsPointer_t
Definition TXMLEngine.h:18
void * XMLDocPointer_t
Definition TXMLEngine.h:20
void * XMLAttrPointer_t
Definition TXMLEngine.h:19
const char * GetNSName(XMLNsPointer_t ns)
return name id of namespace
XMLNodePointer_t GetChild(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
returns first child of xmlnode
void FreeDoc(XMLDocPointer_t xmldoc)
frees allocated document data and deletes document itself
XMLNodePointer_t DocGetRootElement(XMLDocPointer_t xmldoc)
returns root node of document
XMLAttrPointer_t GetNextAttr(XMLAttrPointer_t xmlattr)
return next attribute in the list
const char * GetNSReference(XMLNsPointer_t ns)
return reference id of namespace
const char * GetNodeContent(XMLNodePointer_t xmlnode)
get contents (if any) of xmlnode
XMLNsPointer_t GetNS(XMLNodePointer_t xmlnode)
return namespace attribute (if exists)
const char * GetAttrName(XMLAttrPointer_t xmlattr)
return name of the attribute
XMLAttrPointer_t GetFirstAttr(XMLNodePointer_t xmlnode)
return first attribute in the list, namespace (if exists) will be skipped
const char * GetNodeName(XMLNodePointer_t xmlnode)
returns name of xmlnode
XMLDocPointer_t ParseFile(const char *filename, Int_t maxbuf=100000)
Parses content of file and tries to produce xml structures.
const char * GetAttrValue(XMLAttrPointer_t xmlattr)
return value of attribute
XMLNodePointer_t GetNext(XMLNodePointer_t xmlnode, Bool_t realnode=kTRUE)
return next to xmlnode node if realnode==kTRUE, any special nodes in between will be skipped