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
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
27 XMLAttrPointer_t attr = xml.GetFirstAttr(node);
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
39 XMLNodePointer_t child = xml.GetChild(node);
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
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
61
62 // Release memory before exit
63 xml.FreeDoc(xmldoc);
64}
int Int_t
Definition RtypesCore.h:45
ROOT::Detail::TRangeCast< T, true > TRangeDynCast
TRangeDynCast is an adapter class that allows the typed iteration through a TCollection.
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