XmlTools.hpp
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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>
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