XMLParser.h

Go to the documentation of this file.
00001 // Copyright CERN 2012 - Developed in collaboration with GSI
00002 
00003 #ifndef _XMLPARSER_HPP_
00004 #define _XMLPARSER_HPP_
00005 
00006 #include <string>
00007 #include <vector>
00008 #include <iostream>
00009 #include <unistd.h>
00010 
00011 #include <libxml/tree.h>
00012 #include <libxml/parser.h>
00013 #include <libxml/xpath.h>
00014 #include <libxml/xpath.h>
00015 #include <libxml/xpathInternals.h>
00016 #include <libxml/encoding.h>
00017 #include <libxml/xmlwriter.h>
00018 
00019 #include <fesa-core/Exception/FesaException.h>
00020 
00021 #define MY_ENCODING "UTF-8"
00022 
00023 namespace fesa
00024 {
00025 
00030 class AttributeXML
00031 {
00032   public:
00033 
00037     std::string name_;
00038 
00042     std::string value_;
00043 };
00044 
00050 class ElementXML
00051 {
00052   public:
00053 
00057     std::string name_;
00058 
00062     std::string value_;
00063 
00067     std::vector<AttributeXML*> attributeList_;
00068 
00072     std::vector<ElementXML*> childList_;
00073 
00077     ~ElementXML();
00078 };
00079 
00085 class XMLParser
00086 {
00087   public:
00088 
00094     XMLParser(const std::string& fileName, bool validateFile);
00095 
00099     virtual ~XMLParser();
00100 
00105     virtual void createFile();
00106 
00110     virtual void startDocument();
00111 
00115     virtual void endDocument();
00116 
00121     virtual void startElement(const std::string element);
00122 
00128     virtual void writeElement(const std::string element, const std::string elementValue);
00129 
00134     virtual void endElement();
00135 
00140     virtual void writeString(const std::string text);
00141 
00145     virtual void writeNewline();
00146 
00152     virtual void writeAttribute(const std::string attributeName, const std::string attributeValue);
00153 
00160     virtual std::vector<ElementXML*>* extractElementsFromXPath(const std::string& xpathExpr);
00161 
00165     virtual std::vector<ElementXML*>* extractElements(const std::string& elementName);
00166 
00173     virtual AttributeXML* extractAttribute(const std::string& elementName, const std::string& attributeName);
00174 
00175   private:
00176 
00182     void fillElement(xmlNodePtr node, ElementXML* pElement);
00183 
00188     void trimCarrierReturn(std::string& s);
00189 
00196     xmlChar* ConvertInput(const char *in, const char *encoding);
00197 
00201     xmlTextWriterPtr writer_;
00202 
00206     std::string fileName_;
00207 };
00208 
00209 } // fesa
00210 
00211 #endif // XML_PARSER_H_

Generated on 18 Jan 2013 for Fesa by  doxygen 1.6.1