00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef XMLUTILS_H
00019 #define XMLUTILS_H
00020
00021
00022 #include "smbios/compat.h"
00023
00024 #include <libxml/xmlmemory.h>
00025 #include <libxml/parser.h>
00026
00027 #include "ExceptionImpl.h"
00028
00029
00030 #define XERCES_CPP_NAMESPACE_QUALIFIER
00031 #define DOMElement xmlNode
00032 #define DOMNode xmlNode
00033 #define DOMDocument xmlDoc
00034 #define DOMBuilder int
00035 #define SETUP_XML_NAMESPACE
00036 #define XML_NAMESPACE
00037 #define CHECK_VERSION_COMPAT LIBXML_TEST_VERSION
00038 #define xmlDocGetRootElement(doc) xmlDocGetRootElement(const_cast<xmlDocPtr>(doc))
00039 #define InitXML() \
00040 do { \
00041 } while(0)
00042 #define FiniXML() do{}while(0)
00043 #define xmlFreeParser(parser) do{parser=0;}while(0)
00044 #define xmlFreeDoc(doc) do{xmlFreeDoc(doc); doc=0;}while(0)
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 #if LIBXML_VERSION < 20600
00068
00069 #undef InitXML
00070 #define InitXML() xmlSetGenericErrorFunc(NULL, xmlutils::suppressLibxmlWarnings);
00071 namespace xmlutils
00072 {
00073 void suppressLibxmlWarnings (void *ctx, const char *msg, ...);
00074 }
00075
00076 # define compatXmlReadFile(parser, doc, name) do{UNREFERENCED_PARAMETER(parser); doc = xmlParseFile(name);}while(0)
00077 # define compatXmlReadMemory(parser, doc, ptr, len) do{UNREFERENCED_PARAMETER(parser); doc = xmlParseMemory(ptr, len);}while(0)
00078
00079 #else
00080
00081 # define compatXmlReadFile(parser, doc, name) do{UNREFERENCED_PARAMETER(parser); doc = xmlReadFile(name, \
00082 NULL, \
00083 XML_PARSE_RECOVER | XML_PARSE_NOENT | XML_PARSE_DTDATTR | XML_PARSE_NOWARNING | XML_PARSE_NONET | XML_PARSE_NOCDATA \
00084 );}while(0)
00085 # define compatXmlReadMemory(parser, doc, buf, len) do{UNREFERENCED_PARAMETER(parser);doc = xmlReadMemory(\
00086 buf, \
00087 len, \
00088 NULL, \
00089 NULL, \
00090 XML_PARSE_RECOVER | \
00091 XML_PARSE_NOENT | \
00092 XML_PARSE_DTDATTR | \
00093 XML_PARSE_NOWARNING | \
00094 XML_PARSE_NONET | \
00095 XML_PARSE_NOCDATA \
00096 );}while(0)
00097 #endif
00098
00099
00100 namespace xmlutils
00101 {
00102
00103
00104
00105 DECLARE_EXCEPTION( XmlUtilsException );
00106 DECLARE_EXCEPTION_EX( NotFound, xmlutils, XmlUtilsException );
00107 DECLARE_EXCEPTION_EX( Invalid, xmlutils, XmlUtilsException );
00108
00109
00110
00111 DEFINE_EXCEPTION_EX( NotFoundImpl, xmlutils, NotFound );
00112 DEFINE_EXCEPTION_EX( InvalidImpl, xmlutils, Invalid );
00113
00114 std::string safeGetAttribute( const xmlNode *node, const std::string &attr );
00115 DOMBuilder *getParser( );
00116
00117 xmlNodePtr findElement( xmlNodePtr root, const std::string elementName, const std::string &attribute, const std::string &value );
00118 xmlNodePtr findElementWithNumericAttr( xmlNodePtr root, const std::string elementName, const std::string &attribute, long value);
00119
00120 std::string getNodeText( xmlNodePtr elem );
00121 int getNumberFromXmlAttr( xmlNodePtr element, const std::string field, int base );
00122 }
00123
00124 #endif