Main Page | Namespace List | Class Hierarchy | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

XmlUtils.h

Go to the documentation of this file.
00001 // vim:expandtab:autoindent:tabstop=4:shiftwidth=4:filetype=c:cindent:
00002 /*
00003  * Copyright (C) 2005 Dell Inc.
00004  *  by Michael Brown <Michael_E_Brown@dell.com>
00005  * Licensed under the Open Software License version 2.1
00006  *
00007  * Alternatively, you can redistribute it and/or modify
00008  * it under the terms of the GNU General Public License as published
00009  * by the Free Software Foundation; either version 2 of the License,
00010  * or (at your option) any later version.
00011 
00012  * This program is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00015  * See the GNU General Public License for more details.
00016  */
00017 
00018 #ifndef XMLUTILS_H
00019 #define XMLUTILS_H
00020 
00021 // compat header should always be first header
00022 #include "smbios/compat.h"
00023 
00024 #include <libxml/xmlmemory.h>
00025 #include <libxml/parser.h>
00026 
00027 #include "ExceptionImpl.h"
00028 
00029 // xerces compat stuff until transition is complete
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 XML_PARSE_RECOVER = 1 : recover on errors
00048 XML_PARSE_NOENT = 2 : substitute entities
00049 XML_PARSE_DTDLOAD = 4 : load the external subset
00050 XML_PARSE_DTDATTR = 8 : default DTD attributes
00051 XML_PARSE_DTDVALID = 16 : validate with the DTD
00052 XML_PARSE_NOERROR = 32 : suppress error reports
00053 XML_PARSE_NOWARNING = 64 : suppress warning reports
00054 XML_PARSE_PEDANTIC = 128 : pedantic error reporting
00055 XML_PARSE_NOBLANKS = 256 : remove blank nodes
00056 XML_PARSE_SAX1 = 512 : use the SAX1 interface internally
00057 XML_PARSE_XINCLUDE = 1024 : Implement XInclude substitition
00058 XML_PARSE_NONET = 2048 : Forbid network access
00059 XML_PARSE_NODICT = 4096 : Do not reuse the context dictionnary
00060 XML_PARSE_NSCLEAN = 8192 : remove redundant namespaces declarations
00061 XML_PARSE_NOCDATA = 16384 : merge CDATA as text nodes
00062 XML_PARSE_NOXINCNODE = 32768 : do not generate XINCLUDE START/END nodes
00063 XML_PARSE_COMPACT = 65536 : compact small text nodes
00064            */
00065 
00066 // We program to the 2.6 API. Here are some backwards compat stuff
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     // declare exceptions
00104     //    Internal users should catch() these...
00105     DECLARE_EXCEPTION( XmlUtilsException );
00106     DECLARE_EXCEPTION_EX( NotFound, xmlutils, XmlUtilsException );
00107     DECLARE_EXCEPTION_EX( Invalid, xmlutils, XmlUtilsException );
00108 
00109     // Since this is also a private header, define them
00110     //  internal use only inside XmlUtils.cpp
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

Generated on Wed Apr 11 16:25:10 2007 for SMBIOS Library by doxygen 1.3.5