00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00025 #ifndef DOM_TOOLS_H
00026 #define DOM_TOOLS_H
00027
00028 using namespace std;
00029
00030 #include <xercesc/dom/DOM.hpp>
00031 #include <xercesc/util/BinInputStream.hpp>
00032 #include <xercesc/dom/DOMInputSource.hpp>
00033 #include <xercesc/util/PlatformUtils.hpp>
00034 #include <xercesc/parsers/XercesDOMParser.hpp>
00035 #include <xercesc/sax/HandlerBase.hpp>
00036 #include <xercesc/util/XMLString.hpp>
00037 #include <xercesc/util/TransService.hpp>
00038
00039 #include <string>
00040 #include <vector>
00041 #include <iostream>
00042 #include <sstream>
00043 #include <fstream>
00044 #include <locale.h>
00045
00046
00047
00048
00049 ostream & operator << (ostream & target, xercesc::DOMNode * toWrite);
00050 ostream & operator << (ostream & target, const XMLCh * x);
00051
00052
00053
00054
00055 class BOSSString
00056 {
00057 public:
00058 unsigned char* data;
00059 BOSSString & operator = (const XMLCh* source);
00060 };
00061
00062 namespace BOSS{
00063
00064 typedef vector< xercesc::DOMNode* > DOMNodeVector;
00065
00066
00067
00068
00069 bool hasAttribute(const xercesc::DOMNode* n, string as);
00070 bool hasAttribute(const xercesc::DOMElement * e, string as);
00071 string getAttrByName(const xercesc::DOMElement * e, string as);
00072 string getAttrByName(const xercesc::DOMNode * n, string as);
00073
00074 void createLists(const xercesc::DOMNode * start_node, const char* node_name, DOMNodeVector & list);
00075 void setAttribute(xercesc::DOMElement* e, const char* name, const char* value);
00076 xercesc::DOMNodeList* getElementsByTagName (const xercesc::DOMElement* e, const char* name);
00077 xercesc::DOMNodeList* getElementsByTagName (const xercesc::DOMDocument* d, const char* name);
00078 xercesc::DOMElement* createElement(xercesc::DOMDocument* doc, const char* name);
00079 bool compareNodeName(const xercesc::DOMNode* node, const string & name);
00080 string getNodeName(const xercesc::DOMNode* node);
00081 string getNodeValue(const xercesc::DOMNode* node);
00082
00083 void* getUserData(const xercesc::DOMNode* node);
00084 void setUserData(const xercesc::DOMNode* node, void* data);
00085
00086 void initXML();
00087 void initTranscoder();
00088 xercesc::XMLTranscoder* initTranscoder(string name);
00089 xercesc::DOMDocument* parseXMLFile(const char* xml_file);
00090 xercesc::DOMDocument* parseXMLFromMemory(const string input);
00091
00092
00093 class MMFInputStream :
00094 public xercesc::BinInputStream
00095 {
00096
00097 public:
00098 MMFInputStream(const char *xml)
00099 {
00100 m_xml = xml;
00101 m_pStart = (XMLByte*) xml;
00102 m_pCurrent = m_pStart;
00103 }
00104
00105 virtual ~MMFInputStream(void)
00106 {
00107 }
00108
00109
00110 public:
00111
00112 virtual unsigned int curPos() const
00113 {
00114 return m_pCurrent - m_pStart;
00115 }
00116
00117 virtual unsigned int readBytes(XMLByte* const toFill, const unsigned int maxToRead)
00118 {
00119
00120 unsigned int nRead = strlen(m_xml) - curPos();
00121 if (nRead > maxToRead)
00122 nRead = maxToRead;
00123
00124 memcpy(toFill, m_pCurrent, nRead);
00125 m_pCurrent += nRead;
00126 return nRead;
00127 }
00128
00129 protected:
00130
00131 const char* m_xml;
00132 XMLByte* m_pStart;
00133 XMLByte* m_pCurrent;
00134
00135 };
00136
00137 class MMFInputSource :
00138 public xercesc::DOMInputSource
00139 {
00140
00141 public:
00142
00143 MMFInputSource(const char *xml)
00144 {
00145 m_xml = xml;
00146 }
00147
00148 virtual ~MMFInputSource(void)
00149 {
00150 }
00151
00152 virtual xercesc::BinInputStream* makeStream() const
00153 {
00154 return new MMFInputStream(m_xml);
00155 }
00156
00157 const XMLCh * getEncoding () const {return NULL;}
00158 const XMLCh * getPublicId () const {return NULL;}
00159 const XMLCh * getSystemId () const {return NULL;}
00160 const XMLCh * getBaseURI () const {return NULL;}
00161 void setEncoding (const XMLCh *const encodingStr){}
00162 void setPublicId (const XMLCh *const publicId){}
00163 void setSystemId (const XMLCh *const systemId){}
00164 void setBaseURI (const XMLCh *const baseURI){}
00165 void setIssueFatalErrorIfNotFound (const bool flag){}
00166 bool getIssueFatalErrorIfNotFound () const{return false;}
00167 void release (){}
00168
00169
00170 protected:
00171
00172 const char* m_xml;
00173
00174 };
00175
00176 };
00177
00178 #endif