XmlTools.hpp

00001 /*
00002 
00003 Copyright (C) University of Oxford, 2005-2011
00004 
00005 University of Oxford means the Chancellor, Masters and Scholars of the
00006 University of Oxford, having an administrative office at Wellington
00007 Square, Oxford OX1 2JD, UK.
00008 
00009 This file is part of Chaste.
00010 
00011 Chaste is free software: you can redistribute it and/or modify it
00012 under the terms of the GNU Lesser General Public License as published
00013 by the Free Software Foundation, either version 2.1 of the License, or
00014 (at your option) any later version.
00015 
00016 Chaste is distributed in the hope that it will be useful, but WITHOUT
00017 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00019 License for more details. The offer of Chaste under the terms of the
00020 License is subject to the License being interpreted in accordance with
00021 English Law and subject to any action against the University of Oxford
00022 being under the jurisdiction of the English Courts.
00023 
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with Chaste. If not, see <http://www.gnu.org/licenses/>.
00026 
00027 */
00028 
00029 #ifndef XMLTOOLS_HPP_
00030 #define XMLTOOLS_HPP_
00031 
00032 #include <string>
00033 #include <vector>
00034 
00035 #include <xercesc/dom/DOMDocument.hpp>
00036 #include <xercesc/dom/DOMNode.hpp>
00037 #include <xercesc/dom/DOMElement.hpp>
00038 #include <xercesc/util/XercesDefs.hpp> // XMLCh
00039 
00040 #include <xsd/cxx/version.hxx>
00041 #include <xsd/cxx/xml/string.hxx>
00042 #include <xsd/cxx/xml/dom/auto-ptr.hxx>
00043 #include <xsd/cxx/tree/error-handler.hxx>
00044 #include <xsd/cxx/tree/elements.hxx>
00045 
00050 #define X(str) xsd::cxx::xml::string(str).c_str()
00051 
00056 #define X2C(str) xsd::cxx::xml::transcode<char>(str)
00057 
00061 class XmlTools
00062 {
00063 public:
00072     static xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument> ReadXmlFile(
00073         const std::string& rFileName,
00074         const ::xsd::cxx::tree::properties<char>& rProps,
00075         bool validate=true);
00076 
00086     static void Finalize();
00087 
00091     class Finalizer
00092     {
00093     public:
00098         Finalizer(bool init);
00099 
00103         ~Finalizer();
00104     };
00105 
00120     static xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument> ReadFileToDomDocument(
00121         const std::string& rFileName,
00122         ::xsd::cxx::xml::error_handler<char>& rErrorHandler,
00123         const ::xsd::cxx::tree::properties<char>& rProps,
00124         bool validate=true);
00125 
00133     static void PrintNode(const std::string& rMsg, xercesc::DOMNode* pNode, bool showChildren=false);
00134 
00145     static xercesc::DOMElement* SetNamespace(xercesc::DOMDocument* pDocument,
00146                                              xercesc::DOMElement* pElement,
00147                                              const std::string& rNamespace);
00148 
00159     static xercesc::DOMElement* SetNamespace(xercesc::DOMDocument* pDocument,
00160                                              xercesc::DOMElement* pElement,
00161                                              const XMLCh* pNamespace);
00162 
00174     static void WrapContentInElement(xercesc::DOMDocument* pDocument,
00175                                      xercesc::DOMElement* pElement,
00176                                      const XMLCh* pNewElementLocalName);
00177 
00183     static std::vector<xercesc::DOMElement*> GetChildElements(xercesc::DOMElement* pElement);
00184 
00191     static std::vector<xercesc::DOMElement*> FindElements(xercesc::DOMElement* pContextElement,
00192                                                           const std::string& rPath);
00193 
00203     static void FindElements(xercesc::DOMElement* pContextElement,
00204                              const std::vector<std::string>& rNames,
00205                              std::vector<xercesc::DOMElement*>& rResults,
00206                              unsigned depth=0);
00207 
00215     static std::string EscapeSpaces(const std::string& rPath);
00216 
00217 };
00218 
00219 #endif /* XMLTOOLS_HPP_ */
Generated on Thu Dec 22 13:00:06 2011 for Chaste by  doxygen 1.6.3