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
70Int_t TDOMParser::ParseFile(const char *filename)
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
94Int_t TDOMParser::ParseBuffer(const char *buffer, Int_t len)
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:364
virtual TXMLDocument * GetXMLDocument() const
Returns the TXMLDocument.
Int_t ParseContext()
Creates a XML document for the parser.
virtual ~TDOMParser()
TDOMParser destructor, it calls ReleaseUnderlying().
TDOMParser()
TDOMParser constructor.
virtual void ReleaseUnderlying()
Release any existing document.
TXMLDocument * fTXMLDoc
xmlDoc
Definition TDOMParser.h:23
virtual Int_t ParseBuffer(const char *buffer, Int_t len)
It parses a buffer, much like ParseFile().
virtual Int_t ParseFile(const char *filename)
Parse the XML file where filename is the XML file name.
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.