xrootd
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
XrdXmlReader Class Referenceabstract

#include <XrdXmlReader.hh>

Inheritance diagram for XrdXmlReader:
Inheritance graph
[legend]

Public Member Functions

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
 
 XrdXmlReader ()
 Constructor & Destructor.
 
virtual ~XrdXmlReader ()
 

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.

Constructor & Destructor Documentation

◆ XrdXmlReader()

XrdXmlReader::XrdXmlReader ( )
inline

Constructor & Destructor.

◆ ~XrdXmlReader()

virtual XrdXmlReader::~XrdXmlReader ( )
inlinevirtual

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 XrdXmlRdrTiny, and XrdXmlRdrXml2.

◆ 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 XrdXmlRdrTiny, and XrdXmlRdrXml2.

◆ 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 XrdXmlRdrTiny, and XrdXmlRdrXml2.

◆ GetReader()

static 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.

◆ 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 XrdXmlRdrTiny, and XrdXmlRdrXml2.

◆ Init()

static 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.

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