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 <xercesc/util/PlatformUtils.hpp>
00025 #include <xercesc/dom/DOM.hpp>
00026 #include <xercesc/dom/DOMImplementationLS.hpp>
00027 #include <xercesc/framework/StdOutFormatTarget.hpp>
00028 #include <xercesc/framework/LocalFileFormatTarget.hpp>
00029 #include <xercesc/parsers/XercesDOMParser.hpp>
00030 #include <xercesc/util/XMLUni.hpp>
00031 #include <xercesc/framework/MemBufInputSource.hpp>
00032 #include <xercesc/framework/Wrapper4InputSource.hpp>
00033 
00034 #include "ExceptionImpl.h"
00035 
00036 #define X(x)  XMLString::transcode(x)
00037 
00038 #define xmlDocGetRootElement(doc) doc->getDocumentElement()
00039 #define SETUP_XML_NAMESPACE XERCES_CPP_NAMESPACE_USE
00040 #define XML_NAMESPACE XERCES_CPP_NAMESPACE_QUALIFIER
00041 #define CHECK_VERSION_COMPAT
00042 #define InitXML XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::Initialize
00043 #define FiniXML XERCES_CPP_NAMESPACE_QUALIFIER XMLPlatformUtils::Terminate
00044 #define xmlFreeParser(parser) do{parser->resetDocumentPool(); parser->release();parser=0;}while(0)
00045 #define xmlFreeDoc(doc) do{doc=0;}while(0)
00046 
00047 #define compatXmlReadFile(parser, doc, name) do{try{doc = parser->parseURI(name);}catch( const std::exception & ){}}while(0)
00048 
00049                 // create SAX input source
00050                 // wrap it with a DOM input source. DOM wrapper adopts the
00051                 // SAX, no need to delete.
00052 #define compatXmlReadMemory(parser, doc, str, len) \
00053     do{ \
00054         try \
00055         {   \
00056             MemBufInputSource* memBufIs = new MemBufInputSource(    \
00057                 reinterpret_cast<const XMLByte*>(stdXml),   \
00058                 len,    \
00059                 "standard_xml", \
00060                 false );   \
00061             DOMInputSource* Is = new Wrapper4InputSource( memBufIs );   \
00062             doc = parser->parse( *Is ); \
00063             delete Is;  \
00064         }   \
00065         catch (const std::exception &)\
00066         {}  \
00067     }while(0)
00068 
00069 namespace xmlutils
00070 {
00071 
00072     // declare exceptions
00073     //    Internal users should catch() these...
00074     DECLARE_EXCEPTION( XmlUtilsException );
00075     DECLARE_EXCEPTION_EX( NotFound, xmlutils, XmlUtilsException );
00076     DECLARE_EXCEPTION_EX( Invalid, xmlutils, XmlUtilsException );
00077 
00078     // Since this is also a private header, define them
00079     //  internal use only inside XmlUtils.cpp
00080     DEFINE_EXCEPTION_EX( NotFoundImpl, xmlutils, NotFound );
00081     DEFINE_EXCEPTION_EX( InvalidImpl, xmlutils, Invalid );
00082 
00083     XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *castNode2Element(       XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node );
00084     const XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *castNode2Element( const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node );
00085 
00086     std::string safeXMLChToString( const XMLCh *src );
00087 
00088     std::string safeGetAttribute( const XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *node, const std::string &attr );
00089 
00090     XERCES_CPP_NAMESPACE_QUALIFIER DOMBuilder *getParser( );
00091 
00092     XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *findElement( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *root, const std::string elementName, const std::string &attribute, const std::string &value );
00093     XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *findElementWithNumericAttr( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *root, const std::string elementName, const std::string &attribute, long value);
00094 
00095     std::string getNodeText( XERCES_CPP_NAMESPACE_QUALIFIER DOMNode *elem );
00096     int getNumberFromXmlAttr( XERCES_CPP_NAMESPACE_QUALIFIER DOMElement *element, const std::string field, int base );
00097 }
00098 
00099 #endif

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