fesa-core  4.3.1
fesa::XMLParser Class Reference

This class offers functions to extract information from an XML file. It uses the xPath functions of the library libXML. More...

#include <XMLParser.h>

Inherits noncopyable.

Public Member Functions

 XMLParser (const std::string &fileName, bool validateFile)
 constructor More...
 
 XMLParser (const std::string &data)
 constructor More...
 
virtual ~XMLParser ()
 destructor
 
virtual void createFile ()
 this method starts the creation of an xml file. It is the first method you have to call in order to create the xml file
 
virtual void startDocument ()
 this method writes the xml directive into the file, starting the xml document
 
virtual void endDocument ()
 this method ends the xml document, freeing the xml writer interface
 
virtual void startElement (const std::string element)
 this method starts a new element tag More...
 
virtual void writeElement (const std::string element, const std::string elementValue)
 this method writes an element and its value into the current file More...
 
virtual void endElement ()
 this method ends a new element tag
 
virtual void writeString (const std::string text)
 this method writes a string into the xml document More...
 
virtual void writeNewline ()
 this method starts a new line in the xml document
 
virtual void writeAttribute (const std::string attributeName, const std::string attributeValue)
 this method adds an attribute to the current element that is being edited More...
 
virtual boost::optional
< std::vector
< boost::shared_ptr
< ElementXML > > > 
extractElementsFromXPath (const std::string &xpathExpr) const
 Extracts information from an XML file by searching for an xPath expression. More...
 
virtual boost::optional
< boost::ptr_vector
< ElementXML > > 
getElementsFromXPath (const std::string &xpathExpression) const
 Retrieve the elements identified by the XPath expression from the XML file. More...
 
std::auto_ptr< ElementXMLgetElementFromXPath (const std::string &xpathExpression) const
 Retrieve the first element identified by the XPath expression from the XML file. More...
 
std::string getElementContentFromXPath (const std::string &xpath) const
 
virtual boost::optional
< std::vector
< boost::shared_ptr
< ElementXML > > > 
extractElements (const std::string &elementName) const
 extracts information from an XML file by searching for a XML element name More...
 
virtual boost::optional
< boost::ptr_vector
< ElementXML > > 
getElements (const std::string &elementName) const
 Retrieve the elements with the given name from the XML file. More...
 
virtual boost::optional
< AttributeXML
extractAttribute (const std::string &elementName, const std::string &attributeName) const
 Extracts information from an XML file by searching for a XML attribute in an XML element. More...
 

Detailed Description

This class offers functions to extract information from an XML file. It uses the xPath functions of the library libXML.

Constructor & Destructor Documentation

fesa::XMLParser::XMLParser ( const std::string &  fileName,
bool  validateFile 
)

constructor

Parameters
fileNamepath of the file that represents the xml element
validateFileif true, file is validated
fesa::XMLParser::XMLParser ( const std::string &  data)

constructor

Parameters
datathe in-memory xml data to parse

Member Function Documentation

boost::optional< AttributeXML > fesa::XMLParser::extractAttribute ( const std::string &  elementName,
const std::string &  attributeName 
) const
virtual

Extracts information from an XML file by searching for a XML attribute in an XML element.

Parameters
elementNameelement that contains the attribute
attributeNameattribute to look for
boost::optional< std::vector< boost::shared_ptr< ElementXML > > > fesa::XMLParser::extractElements ( const std::string &  elementName) const
virtual

extracts information from an XML file by searching for a XML element name

Deprecated:
(see getElements)
boost::optional< std::vector< boost::shared_ptr< ElementXML > > > fesa::XMLParser::extractElementsFromXPath ( const std::string &  xpathExpr) const
virtual

Extracts information from an XML file by searching for an xPath expression.

Deprecated:
(see getElementsFromXPath)
Parameters
xpathExprxpath expression to retrieve the elements
Returns
The child elements of the xPath expression. If error, nothing.
std::string fesa::XMLParser::getElementContentFromXPath ( const std::string &  xpath) const

Returns the content of the first element corresponding to xpath.

Parameters
xpaththe xpath of the element content to retrieve
Exceptions
FesaExceptionif the xpath has no corresponding element
std::auto_ptr< ElementXML > fesa::XMLParser::getElementFromXPath ( const std::string &  xpathExpression) const

Retrieve the first element identified by the XPath expression from the XML file.

Parameters
xpathExpressionThe XPath expression
Returns
an auto-pointer containing the corresponding ElementXML
Exceptions
FesaExceptionif the xpath has no corresponding element
boost::optional< boost::ptr_vector< ElementXML > > fesa::XMLParser::getElements ( const std::string &  elementName) const
virtual

Retrieve the elements with the given name from the XML file.

Parameters
elementNameThe elements' name
boost::optional< boost::ptr_vector< ElementXML > > fesa::XMLParser::getElementsFromXPath ( const std::string &  xpathExpression) const
virtual

Retrieve the elements identified by the XPath expression from the XML file.

Parameters
xpathExpressionThe XPath expression
void fesa::XMLParser::startElement ( const std::string  element)
virtual

this method starts a new element tag

Parameters
elementthe tag of the element to start
void fesa::XMLParser::writeAttribute ( const std::string  attributeName,
const std::string  attributeValue 
)
virtual

this method adds an attribute to the current element that is being edited

Parameters
attributeNamename of the attribute
attributeValuevalue of the attribute
void fesa::XMLParser::writeElement ( const std::string  element,
const std::string  elementValue 
)
virtual

this method writes an element and its value into the current file

Parameters
elementto write
elementValuevalue of the element
void fesa::XMLParser::writeString ( const std::string  text)
virtual

this method writes a string into the xml document

Parameters
textto write in the xml document

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