XRootD
XrdXmlReader Class Referenceabstract

#include <XrdXmlReader.hh>

+ Inheritance diagram for XrdXmlReader:
+ Collaboration diagram for XrdXmlReader:

Public Member Functions

 XrdXmlReader ()
 Constructor & Destructor. More...
 
virtual ~XrdXmlReader ()
 
virtual bool GetAttributes (const char **aname, char **aval)=0
 
virtual int GetElement (const char **ename, bool reqd=false)=0
 
virtual const char * GetError (int &ecode)=0
 
virtual char * GetText (const char *ename, bool reqd=false)=0
 

Static Public Member Functions

static XrdXmlReaderGetReader (const char *fname, const char *enc=0, const char *impl=0)
 
static bool Init (const char *impl=0)
 

Detailed Description

The XrdXmlReader object provides a virtual interface to read xml files, irrespective of the underlying mplementation. Obtain an XML reader using GetRead(). You may also wish to call Init() prior to obtaining a reader in multi-threader applications. As some implementations may not be MT-safe. See GetReader() for more information.

Definition at line 40 of file XrdXmlReader.hh.

Constructor & Destructor Documentation

◆ XrdXmlReader()

XrdXmlReader::XrdXmlReader ( )
inline

Constructor & Destructor.

Definition at line 164 of file XrdXmlReader.hh.

164 {}

◆ ~XrdXmlReader()

virtual XrdXmlReader::~XrdXmlReader ( )
inlinevirtual

Definition at line 165 of file XrdXmlReader.hh.

165 {}

Member Function Documentation

◆ GetAttributes()

virtual bool XrdXmlReader::GetAttributes ( const char **  aname,
char **  aval 
)
pure 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.

Implemented in XrdXmlRdrXml2, and XrdXmlRdrTiny.

Referenced by XrdXmlMetaLink::Convert().

+ Here is the caller graph for this function:

◆ GetElement()

virtual int XrdXmlReader::GetElement ( const char **  ename,
bool  reqd = false 
)
pure 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.

Implemented in XrdXmlRdrXml2, and XrdXmlRdrTiny.

Referenced by XrdXmlMetaLink::Convert().

+ Here is the caller graph for this function:

◆ GetError()

virtual const char* XrdXmlReader::GetError ( int &  ecode)
pure virtual

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.

Implemented in XrdXmlRdrXml2, and XrdXmlRdrTiny.

Referenced by GetReader().

+ Here is the caller graph for this function:

◆ GetReader()

XrdXmlReader * XrdXmlReader::GetReader ( const char *  fname,
const char *  enc = 0,
const char *  impl = 0 
)
static

Get a reader object to parse an XML file.

Parameters
fnamePointer to the filepath of the file to be parsed.
encPointer to the encoding specification. When nil, UTF-8 is used. Currently, this parameter is ignored.
implPointer to the desired implementation. When nil, the default implementation, tinyxml, is used. The following are supported

tinyxml - builtin xml reader. Each instance is independent Since it builds a full DOM tree in memory, it is only good for small amounts of xml. Certain esoteric xml features are not supported.

libxml2 - full-fledged xml reader. Instances are not independent if multiple uses involve setting callbacks, allocators, or I/O overrides. For MT-safeness, it must be initialized in the main thread (see Init() below). It is used in streaming mode and is good for large documents.

Returns
!0 Pointer to an XML reader object.
=0 An XML reader object could not be created; errno holds the error code of the reason.

Definition at line 43 of file XrdXmlReader.cc.

45 {
46  XrdXmlReader *rP;
47  int rc;
48  bool aOK;
49 
50 // Check if this is the default implementation
51 // c
52  if (!impl || !strcmp(impl, "tinyxml"))
53  {rP = new XrdXmlRdrTiny(aOK, fname, enc);
54  if (aOK) return rP;
55  rP->GetError(rc);
56  delete rP;
57  errno = (rc ? rc : ENOTSUP);
58  return 0;
59  }
60 
61 // Check for he full blown xml implementation
62 //
63 #ifdef HAVE_XML2
64  if (!strcmp(impl, "libxml2"))
65  {rP = new XrdXmlRdrXml2(aOK, fname, enc);
66  if (aOK) return rP;
67  rP->GetError(rc);
68  delete rP;
69  errno = (rc ? rc : ENOTSUP);
70  return 0;
71  }
72 #endif
73 
74 // Add additional implementations here
75 //
76 
77 // Not supported
78 //
79  errno = ENOTSUP;
80  return 0;
81 }
virtual const char * GetError(int &ecode)=0

References GetError().

Referenced by XrdXmlMetaLink::Convert().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ GetText()

virtual char* XrdXmlReader::GetText ( const char *  ename,
bool  reqd = false 
)
pure 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().

Implemented in XrdXmlRdrXml2, and XrdXmlRdrTiny.

◆ Init()

bool XrdXmlReader::Init ( const char *  impl = 0)
static

Preinitialze the desired implementation for future use. This is meant to be used in multi-threaded applications, as some implementation must be initialized using the main thread before spawning other threads. An exmaple is libxml2 which is generally MT-unsafe unles preinitialized.

Parameters
implPointer to the desired implementation. When nil, the default implementation is used. Currently, only "libxml2" and "tinyxml" are supported.
Returns
true Initialization suceeded.
false Initialization failed, errno has the reason.

Definition at line 87 of file XrdXmlReader.cc.

88 {
89 // Check if this is the default implementation
90 //
91  if (!impl || !strcmp(impl, "tinyxml")) return true;
92 
93 // Check for the whole hog implmenetation
94 //
95 #ifdef HAVE_XML2
96  if (!strcmp(impl, "libxml2")) {return XrdXmlRdrXml2::Init();}
97 #endif
98 
99 // Add additional implementations here
100 //
101 
102 // Not supported
103 //
104  errno = ENOTSUP;
105  return false;
106 }
static bool Init()

References XrdXmlRdrXml2::Init().

+ Here is the call graph for this function:

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