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:
00071     static xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument> ReadXmlFile(
00072         const std::string& rFileName,
00073         const ::xsd::cxx::tree::properties<char>& rProps);
00074 
00084     static void Finalize();
00085 
00089     class Finalizer
00090     {
00091     public:
00096         Finalizer(bool init);
00097 
00101         ~Finalizer();
00102     };
00103 
00117     static xsd::cxx::xml::dom::auto_ptr<xercesc::DOMDocument> ReadFileToDomDocument(
00118         const std::string& rFileName,
00119         ::xsd::cxx::xml::error_handler<char>& rErrorHandler,
00120         const ::xsd::cxx::tree::properties<char>& rProps);
00121 
00129     static void PrintNode(const std::string& rMsg, xercesc::DOMNode* pNode, bool showChildren=false);
00130 
00141     static xercesc::DOMElement* SetNamespace(xercesc::DOMDocument* pDocument,
00142                                              xercesc::DOMElement* pElement,
00143                                              const std::string& rNamespace);
00144 
00155     static xercesc::DOMElement* SetNamespace(xercesc::DOMDocument* pDocument,
00156                                              xercesc::DOMElement* pElement,
00157                                              const XMLCh* pNamespace);
00158 
00170     static void WrapContentInElement(xercesc::DOMDocument* pDocument,
00171                                      xercesc::DOMElement* pElement,
00172                                      const XMLCh* pNewElementLocalName);
00173 
00179     static std::vector<xercesc::DOMElement*> GetChildElements(xercesc::DOMElement* pElement);
00180 
00187     static std::vector<xercesc::DOMElement*> FindElements(xercesc::DOMElement* pContextElement,
00188                                                           const std::string& rPath);
00189 
00199     static void FindElements(xercesc::DOMElement* pContextElement,
00200                              const std::vector<std::string>& rNames,
00201                              std::vector<xercesc::DOMElement*>& rResults,
00202                              unsigned depth=0);
00203 
00211     static std::string EscapeSpaces(const std::string& rPath);
00212 
00213 };
00214 
00215 #endif /* XMLTOOLS_HPP_ */

Generated on Tue May 31 14:31:41 2011 for Chaste by  doxygen 1.5.5