XRootD
Loading...
Searching...
No Matches
XrdXmlRdrXml2 Class Reference

#include <XrdXmlRdrXml2.hh>

+ Inheritance diagram for XrdXmlRdrXml2:
+ Collaboration diagram for XrdXmlRdrXml2:

Public Member Functions

 XrdXmlRdrXml2 (bool &aOK, const char *fname, const char *enc=0)
 Constructor & Destructor.
 
virtual ~XrdXmlRdrXml2 ()
 
virtual void Free (void *strP)
 
virtual bool GetAttributes (const char **aname, char **aval)
 
virtual int GetElement (const char **ename, bool reqd=false)
 
virtual const char * GetError (int &ecode)
 
virtual char * GetText (const char *ename, bool reqd=false)
 
- Public Member Functions inherited from XrdXmlReader
 XrdXmlReader ()
 Constructor & Destructor.
 
virtual ~XrdXmlReader ()
 

Static Public Member Functions

static bool Init ()
 
- Static Public Member Functions inherited from XrdXmlReader
static XrdXmlReaderGetReader (const char *fname, const char *enc=0, const char *impl=0)
 
static bool Init (const char *impl=0)
 

Detailed Description

Definition at line 40 of file XrdXmlRdrXml2.hh.

Constructor & Destructor Documentation

◆ XrdXmlRdrXml2()

XrdXmlRdrXml2::XrdXmlRdrXml2 ( bool & aOK,
const char * fname,
const char * enc = 0 )

Constructor & Destructor.

Definition at line 103 of file XrdXmlRdrXml2.cc.

104{
105// Initialize the standard values
106//
107 encType = (enc ? strdup(enc) : 0);
108 eCode = 0;
109 *eText = 0;
110 doDup = true; // We always duplicate memory to avoid allocator issues
111 debug = getenv("XrdXmlDEBUG") != 0;
112
113// Get a file reader
114//
115 if (!(reader = xmlNewTextReaderFilename(fname)))
116 {if ((eCode = errno))
117 {size_t size = sizeof(eText) - 1;
118 strncpy(eText, XrdSysE2T(errno), size);
119 eText[size] = '\0';
120 }
121 else strcpy(eText, "Unknown error opening input file");
122 aOK = false;
123 } else aOK = true;
124}
const char * XrdSysE2T(int errcode)
Definition XrdSysE2T.cc:99

References XrdSysE2T().

+ Here is the call graph for this function:

◆ ~XrdXmlRdrXml2()

XrdXmlRdrXml2::~XrdXmlRdrXml2 ( )
virtual

Definition at line 130 of file XrdXmlRdrXml2.cc.

131{
132
133// Tear down the reader
134//
135 xmlFreeTextReader(reader); reader = 0;
136}

Member Function Documentation

◆ Free()

void XrdXmlRdrXml2::Free ( void * strP)
virtual

Definition at line 158 of file XrdXmlRdrXml2.cc.

158{xmlFree(strP);}

◆ GetAttributes()

bool XrdXmlRdrXml2::GetAttributes ( const char ** aname,
char ** aval )
virtual

Get attributes from an XML tag. GetAttributes() should only be called after a successful GetElement() call.

Parameters
anamePointer to an array of attribute names whose values are to be returned. The last entry in the array must be nil.
avalPointer to an array where the corresponding attribute values are to be placed in 1-to-1 correspondence. The values must be freed using free().
Returns
true One or more attributes have been returned. false No specified attributes were found.

Implements XrdXmlReader.

Definition at line 164 of file XrdXmlRdrXml2.cc.

165{
166 char *name, *value;
167 int i;
168 bool found = false;
169
170// If we are not at the begining of an element, this is a sequence error
171//
172 if (xmlTextReaderNodeType(reader) != ntElmBeg)
173 {snprintf(eText, sizeof(eText),
174 "Illegal position seeking attribute %s",aname[0]);
175 eCode = EILSEQ;
176 return false;
177 }
178
179// Find the attribute
180//
181 while(xmlTextReaderMoveToNextAttribute(reader))
182 {if ((name = GetName()))
183 {i = 0;
184 while(aname[i] && strcmp(name, aname[i])) i++;
185 xmlFree(name);
186 if (aname[i])
187 {if (!(value = (char *)xmlTextReaderValue(reader))) continue;
188 found = true;
189 if (doDup)
190 {if (aval[i]) free(aval[i]);
191 aval[i] = strdup(value);
192 xmlFree(value);
193 } else {
194 if (aval[i]) xmlFree(aval[i]);
195 aval[i] = value;
196 }
197 }
198 }
199 }
200
201// All done
202//
203 return found;
204}

◆ GetElement()

int XrdXmlRdrXml2::GetElement ( const char ** ename,
bool reqd = false )
virtual

Find an XML tag element.

Parameters
enamePointer to an array of tag names any of which should be searched for. The last entry in the array must be nil. The first element of the array should contain the name of the context tag. Elements are searched only within the scope of that tag. When searching for the first desired tag, use a null string to indicate document scope.
reqdWhen true one of the tag elements listed in ename must be found otherwise an error is generated.
Returns
=0 No specified tag was found. Note that this corresponds to encountering the tag present in ename[0], i.e. scope end. >0 A tag was found, the return value is the index into ename that corresponds to the tag's name.

Implements XrdXmlReader.

Definition at line 210 of file XrdXmlRdrXml2.cc.

211{
212 char *name = 0;
213 int i, nType;
214
215// Scan over to the wanted element
216//
217 while(xmlTextReaderRead(reader) == 1)
218 {nType = xmlTextReaderNodeType(reader);
219 if (nType == ntWSpSig || !(name = GetName())) continue;
220
221 if (nType == ntElmEnd)
222 {if (debug) Debug("getelem:",ename[1],name,ename[0],nType);
223 if (!strcmp(name, ename[0])) break;
224 }
225 else if (nType == ntElmBeg)
226 {i = 1;
227 while(ename[i] && strcmp(name, ename[i])) i++;
228 if (ename[i])
229 {if (debug) Debug("getelem:",ename[i],name,ename[0],nType);
230 xmlFree(name);
231 return i;
232 }
233 if (debug) Debug("getelem:",ename[1],name,ename[0],nType);
234 xmlFree(name);
235 }
236 }
237
238// Free any allocate storage
239//
240 if (name) xmlFree(name);
241
242// This is an error if this element was required
243//
244 if (reqd)
245 {snprintf(eText,sizeof(eText),"Required element '%s' not found in %s",
246 (ename[1] ? ename[1] : "???"), ename[0]);
247 eCode = ESRCH;
248 }
249 return 0;
250}
bool Debug

References Debug.

◆ GetError()

virtual const char * XrdXmlRdrXml2::GetError ( int & ecode)
inlinevirtual

Get the description of the last error encountered.

Parameters
ecodeThe error code associated with the error.
Returns
Pointer to text describing the error. The text may be destroyed on a subsequent call to any other method. Otherwise it is stable. A nil pointer indicates that no error is present.

Implements XrdXmlReader.

Definition at line 51 of file XrdXmlRdrXml2.hh.

51{return ((ecode = eCode) ? eText : 0);}

◆ GetText()

char * XrdXmlRdrXml2::GetText ( const char * ename,
bool reqd = false )
virtual

Get the text portion of an XML tag element. GetText() should only be called after a successful call to GetElement() with a possibly intervening call to GetAttributes().

Parameters
enamePointer to the corresponding tag name.
reqdWhen true text must exist and not be null. Otherwise, an error is generated if the text is missing or null.
Returns
=0 No text found.
!0 Pointer to the tag's text field. It must be free using free().

Implements XrdXmlReader.

Definition at line 265 of file XrdXmlRdrXml2.cc.

266{
267 char *sP, *value = 0;
268
269// Get next element and make sure it exists and is text
270//
271 if (xmlTextReaderRead(reader) == 1
272 && xmlTextReaderNodeType(reader) == ntText)
273 {if ((value = (char *)xmlTextReaderValue(reader)) && !(*value))
274 {xmlFree(value); value = 0;}
275 }
276
277// We did not find a value. If not required return.
278//
279 if (value || !reqd)
280 {if (!doDup || !value) return value;
281 sP = strdup(value);
282 xmlFree(value);
283 return sP;
284 }
285
286// Create error message
287//
288 snprintf(eText,sizeof(eText),"Required %s tag text value not found",ename);
289 eCode = ENOMSG;
290 return 0;
291}

◆ Init()

bool XrdXmlRdrXml2::Init ( )
static

Definition at line 297 of file XrdXmlRdrXml2.cc.

297{xmlInitParser(); return true;}

Referenced by XrdXmlReader::Init().

+ Here is the caller graph for this function:

The documentation for this class was generated from the following files: