Logo ROOT  
Reference Guide
 
Loading...
Searching...
No Matches
TDOMParser.cxx
Go to the documentation of this file.
1// @(#)root/xmlparser:$Id$
2// Author: Jose Lo 12/4/2005
3
4/*************************************************************************
5 * Copyright (C) 1995-2005, Rene Brun and Fons Rademakers. *
6 * All rights reserved. *
7 * *
8 * For the licensing terms see $ROOTSYS/LICENSE. *
9 * For the list of contributors see $ROOTSYS/README/CREDITS. *
10 *************************************************************************/
11
12/**
13\class TDomParser
14\ingroup IO
15
16DOM stands for the Document Object Model; this is an API for
17accessing XML or HTML structured documents.
18The Document Object Model is a platform and language-neutral
19interface that will allow programs and scripts to dynamically
20access and update the content, structure and style of documents.
21
22The parser returns a tree built during the document analysis.
23*/
24
25#include "TDOMParser.h"
26#include "TXMLDocument.h"
27
28#include <libxml/tree.h>
29#include <libxml/parserInternals.h>
30
31
33
34////////////////////////////////////////////////////////////////////////////////
35/// TDOMParser constructor.
36
38{
39}
40
41////////////////////////////////////////////////////////////////////////////////
42/// TDOMParser destructor, it calls ReleaseUnderlying().
43
45{
47}
48
49////////////////////////////////////////////////////////////////////////////////
50/// Release any existing document.
51
53{
54 if (fTXMLDoc) {
55 delete fTXMLDoc;
56 fTXMLDoc = 0;
57 }
58
59 SetParseCode(0);
60
62}
63
64////////////////////////////////////////////////////////////////////////////////
65/// Parse the XML file where filename is the XML file name.
66/// It will create a TXMLDocument if the file is parsed without
67/// any error. It returns parse code error in case of parse error,
68/// see TXMLParser.
69
71{
73
74 fContext = xmlCreateFileParserCtxt(filename);
75
76 if (!fContext) {
77 SetParseCode(-2);
78 return -2;
79 }
80
82
83 if (!fContext->directory) {
84 const char *dir = xmlParserGetDirectory(filename);
85 fContext->directory = (char *)xmlStrdup((const xmlChar *)dir);
86 }
87
88 return ParseContext();
89}
90
91////////////////////////////////////////////////////////////////////////////////
92/// It parses a buffer, much like ParseFile().
93
95{
97
98 fContext = xmlCreateMemoryParserCtxt(buffer, len);
99
100 if (!fContext) {
101 SetParseCode(-2);
102 return -2;
103 }
104
106
107 return ParseContext();
108}
109
110////////////////////////////////////////////////////////////////////////////////
111/// Creates a XML document for the parser.
112/// It returns 0 on success, and
113/// - \b -1 if no XML document was created,
114/// - \b -5 if the document is not well formated,
115/// - \b -6 if document is not valid.
116
118{
119 xmlParseDocument(fContext);
120
121 if (!fContext->myDoc) {
122 SetParseCode(-1);
123 return -1;
124 }
125
126 if (!fContext->wellFormed) {
127 SetParseCode(-5);
128 return -5;
129 }
130
131 if (!fContext->valid) {
132 SetParseCode(-6);
133 return -6;
134 }
135
136 fTXMLDoc = new TXMLDocument(fContext->myDoc);
137
138 return 0;
139}
140
141////////////////////////////////////////////////////////////////////////////////
142/// Returns the TXMLDocument.
143
145{
146 return fTXMLDoc;
147}
#define ClassImp(name)
Definition Rtypes.h:377
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 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 Pixmap_t Pixmap_t PictureAttributes_t attr const char char ret_data h unsigned char height h Atom_t Int_t ULong_t ULong_t unsigned char prop_list Atom_t Atom_t Atom_t Time_t UChar_t len
virtual TXMLDocument * GetXMLDocument() const
Returns the TXMLDocument.
void ReleaseUnderlying() override
Release any existing document.
Int_t ParseContext()
Creates a XML document for the parser.
TDOMParser()
TDOMParser constructor.
Int_t ParseBuffer(const char *buffer, Int_t len) override
It parses a buffer, much like ParseFile().
TXMLDocument * fTXMLDoc
xmlDoc
Definition TDOMParser.h:23
Int_t ParseFile(const char *filename) override
Parse the XML file where filename is the XML file name.
~TDOMParser() override
TDOMParser destructor, it calls ReleaseUnderlying().
TXMLDocument contains a pointer to an xmlDoc structure, after the parser returns a tree built during ...
virtual void InitializeContext()
Initialize parser parameters, such as, disactivate non-standards libxml1 features,...
virtual void SetParseCode(Int_t code)
Set the parse code:
_xmlParserCtxt * fContext
Parse the xml file.
Definition TXMLParser.h:31
virtual void ReleaseUnderlying()
To release any existing document.