<html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1"> <title>HippoDraw Class Library</title> <link href="doxygen.css" rel="stylesheet" type="text/css"> <link href="tabs.css" rel="stylesheet" type="text/css"> <link rel="shortcut icon" href="hippoApp.ico"> </head><body> <!-- Generated by Doxygen 1.6.2 --> <div class="navigation" id="top"> <div class="tabs"> <ul> <li><a href="index.html"><span>Main Page</span></a></li> <li><a href="pages.html"><span>Related Pages</span></a></li> <li><a href="namespaces.html"><span>Namespaces</span></a></li> <li><a href="annotated.html"><span>Classes</span></a></li> <li class="current"><a href="files.html"><span>Files</span></a></li> <li><a href="dirs.html"><span>Directories</span></a></li> </ul> </div> <div class="tabs"> <ul> <li><a href="files.html"><span>File List</span></a></li> <li><a href="globals.html"><span>File Members</span></a></li> </ul> </div> <div class="navpath"><a class="el" href="dir_64d98773e28ad3a986be8bc9397e242e.html">qtxml</a> </div> </div> <div class="contents"> <h1>QtXmlDocument.cxx</h1><a href="QtXmlDocument_8cxx.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment"><a name="l00001"></a>00001 <a name="l00012"></a>00012 <span class="preprocessor">#include "<a class="code" href="QtXmlDocument_8h.html" title="QtXmlDocument class interface.">QtXmlDocument.h</a>"</span> <a name="l00013"></a>00013 <span class="preprocessor">#include "<a class="code" href="QtXmlElement_8h.html" title="hippodraw::QtXmlElement class interface">QtXmlElement.h</a>"</span> <a name="l00014"></a>00014 <span class="preprocessor">#include "<a class="code" href="QtXmlTextNode_8h.html" title="hippodraw::QtXmlTextNode class interface">QtXmlTextNode.h</a>"</span> <a name="l00015"></a>00015 <a name="l00016"></a>00016 <span class="preprocessor">#include <qdir.h></span> <a name="l00017"></a>00017 <span class="preprocessor">#include <qfile.h></span> <a name="l00018"></a>00018 <span class="preprocessor">#include <qfileinfo.h></span> <a name="l00019"></a>00019 <span class="preprocessor">#include <qtextstream.h></span> <a name="l00020"></a>00020 <a name="l00021"></a>00021 <span class="keyword">using</span> std::string; <a name="l00022"></a>00022 <a name="l00023"></a>00023 <span class="keyword">namespace </span>hippodraw { <a name="l00024"></a>00024 <a name="l00025"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#a4e2e819f9a18c457d9d682e12efb735c">00025</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a438f85e2f15a7515109c51094c2ee201" title="A private copy constructor in order to avoid copying.">QtXmlDocument::QtXmlDocument</a> ( <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomdocument.html">QDomDocument</a> document ) <a name="l00026"></a>00026 : m_document ( document ) <a name="l00027"></a>00027 { <a name="l00028"></a>00028 } <a name="l00029"></a>00029 <a name="l00030"></a>00030 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a438f85e2f15a7515109c51094c2ee201" title="A private copy constructor in order to avoid copying.">QtXmlDocument::</a> <a name="l00031"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#a7124185287d25043c1bac721532bad37">00031</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a438f85e2f15a7515109c51094c2ee201" title="A private copy constructor in order to avoid copying.">QtXmlDocument</a> ( <span class="keyword">const</span> std::string & name ) <a name="l00032"></a>00032 { <a name="l00033"></a>00033 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a> = <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomdocument.html">QDomDocument</a> ( name.c_str () ); <a name="l00034"></a>00034 } <a name="l00035"></a>00035 <a name="l00036"></a>00036 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a047c78ba532ebd1d8c0231e77e22077a" title="The dstructor.">QtXmlDocument::</a> <a name="l00037"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#a047c78ba532ebd1d8c0231e77e22077a">00037</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a047c78ba532ebd1d8c0231e77e22077a" title="The dstructor.">~QtXmlDocument</a> () <a name="l00038"></a>00038 { <a name="l00039"></a>00039 } <a name="l00040"></a>00040 <a name="l00041"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#ab6286224905d2d3d64a42d7fb00004da">00041</a> <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> * <a class="code" href="classhippodraw_1_1QtXmlDocument.html#ab6286224905d2d3d64a42d7fb00004da" title="Returns the root document element.">QtXmlDocument::documentElement</a> ( )<span class="keyword"> const</span> <a name="l00042"></a>00042 <span class="keyword"></span>{ <a name="l00043"></a>00043 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomelement.html">QDomElement</a> root = <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a>.<a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomdocument.html#documentElement">documentElement</a> (); <a name="l00044"></a>00044 <a name="l00045"></a>00045 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1QtXmlElement.html" title="An XML element using the Qt XML module.">QtXmlElement</a> ( root ); <a name="l00046"></a>00046 } <a name="l00047"></a>00047 <a name="l00048"></a>00048 <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> * <a name="l00049"></a>00049 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a2c2737eb2591de6a1bc10f176f7f9ca5" title="Creates a new DOM element wrapper object and returns a pointer to it.">QtXmlDocument::</a> <a name="l00050"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#a2c2737eb2591de6a1bc10f176f7f9ca5">00050</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a2c2737eb2591de6a1bc10f176f7f9ca5" title="Creates a new DOM element wrapper object and returns a pointer to it.">createElement</a> ( <span class="keyword">const</span> std::string & tagName ) <a name="l00051"></a>00051 { <a name="l00052"></a>00052 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomelement.html">QDomElement</a> element = <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a>.<a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomdocument.html#createElement">createElement</a> ( tagName.c_str() ); <a name="l00053"></a>00053 <a name="l00054"></a>00054 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1QtXmlElement.html" title="An XML element using the Qt XML module.">QtXmlElement</a> ( element ); <a name="l00055"></a>00055 } <a name="l00056"></a>00056 <a name="l00057"></a>00057 <a class="code" href="classhippodraw_1_1XmlTextNode.html" title="A pure virtual base class of XML DOM Text node wrapper.">XmlTextNode</a> * <a name="l00058"></a>00058 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#afc390cc5c1488c38061c85ac99eea952" title="Creates a new DOM Text node.">QtXmlDocument::</a> <a name="l00059"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#afc390cc5c1488c38061c85ac99eea952">00059</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#afc390cc5c1488c38061c85ac99eea952" title="Creates a new DOM Text node.">createTextNode</a> ( <span class="keyword">const</span> std::string & tag ) <a name="l00060"></a>00060 { <a name="l00061"></a>00061 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomtext.html">QDomText</a> node = <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a>.<a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomdocument.html#createTextNode">createTextNode</a> ( tag.c_str () ); <a name="l00062"></a>00062 <a name="l00063"></a>00063 <span class="keywordflow">return</span> <span class="keyword">new</span> <a class="code" href="classhippodraw_1_1QtXmlTextNode.html" title="An XML Dom text node using the Qt XML module.">QtXmlTextNode</a> ( node ); <a name="l00064"></a>00064 } <a name="l00065"></a>00065 <a name="l00066"></a>00066 <span class="comment">/* virtual */</span> <a name="l00067"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#a2ac36cdcaa4d96cc204b31f6f824a164">00067</a> <span class="keywordtype">void</span> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a2ac36cdcaa4d96cc204b31f6f824a164" title="Appends the root element to the document.">QtXmlDocument::appendChild</a> ( <a class="code" href="classhippodraw_1_1XmlElement.html" title="A pure virtual base class of XML element wrapper.">XmlElement</a> & child ) <a name="l00068"></a>00068 { <a name="l00069"></a>00069 <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1QtXmlElement.html" title="An XML element using the Qt XML module.">QtXmlElement</a> & qtelem <a name="l00070"></a>00070 = dynamic_cast < <span class="keyword">const</span> <a class="code" href="classhippodraw_1_1QtXmlElement.html" title="An XML element using the Qt XML module.">QtXmlElement</a> & > ( child ); <a name="l00071"></a>00071 <a name="l00072"></a>00072 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a>.appendChild ( qtelem.<a class="code" href="classhippodraw_1_1QtXmlNode.html#a19e4ffb1a3a4244a61e5d0db7f604d78" title="The DOM node wrapped by this object.">m_node</a> ); <a name="l00073"></a>00073 } <a name="l00074"></a>00074 <a name="l00075"></a>00075 <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70b" title="Status codes for opening an XML document.">XmlDocument::Status</a> <a name="l00076"></a>00076 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#ae73612e0ead95603984c93efc0711651" title="Saves the document to the file.">QtXmlDocument::</a> <a name="l00077"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#ae73612e0ead95603984c93efc0711651">00077</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#ae73612e0ead95603984c93efc0711651" title="Saves the document to the file.">saveToFile</a> ( <span class="keyword">const</span> std::string & filename ) <a name="l00078"></a>00078 { <a name="l00079"></a>00079 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qfile.html">QFile</a> filedev ( filename.c_str() ); <a name="l00080"></a>00080 <a name="l00081"></a>00081 <span class="preprocessor">#if QT_VERSION < 0x040000</span> <a name="l00082"></a>00082 <span class="preprocessor"></span> <span class="keywordtype">bool</span> ok = filedev.open ( IO_WriteOnly ); <a name="l00083"></a>00083 <span class="preprocessor">#else</span> <a name="l00084"></a>00084 <span class="preprocessor"></span> <span class="keywordtype">bool</span> ok = filedev.open ( QIODevice::WriteOnly ); <a name="l00085"></a>00085 <span class="preprocessor">#endif</span> <a name="l00086"></a>00086 <span class="preprocessor"></span> <a name="l00087"></a>00087 <span class="keywordflow">if</span> ( ! ok ) { <a name="l00088"></a>00088 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba0b72ae8b4c5c7cd0c33ae72a1df64cbb">WriteError</a>; <a name="l00089"></a>00089 } <a name="l00090"></a>00090 <a name="l00091"></a>00091 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qtextstream.html">QTextStream</a> ts ( &filedev ); <a name="l00092"></a>00092 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a>.save ( ts, 2 ); <a name="l00093"></a>00093 filedev.close (); <a name="l00094"></a>00094 <a name="l00095"></a>00095 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70bafdfbdf3247bd36a1f17270d5cec74c9c">Success</a>; <a name="l00096"></a>00096 } <a name="l00097"></a>00097 <a name="l00098"></a>00098 <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70b" title="Status codes for opening an XML document.">XmlDocument::Status</a> <a name="l00099"></a>00099 <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a430062ae22b5cb0ca0e8f9ab88046fc5" title="Sets the content of the XML document from the text in the file filename.">QtXmlDocument::</a> <a name="l00100"></a><a class="code" href="classhippodraw_1_1QtXmlDocument.html#a430062ae22b5cb0ca0e8f9ab88046fc5">00100</a> <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a430062ae22b5cb0ca0e8f9ab88046fc5" title="Sets the content of the XML document from the text in the file filename.">setContent</a> ( <span class="keyword">const</span> std::string & filename ) <a name="l00101"></a>00101 { <a name="l00102"></a>00102 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qfile.html">QFile</a> file ( filename.c_str() ); <a name="l00103"></a>00103 <span class="preprocessor">#if QT_VERSION < 0x040000</span> <a name="l00104"></a>00104 <span class="preprocessor"></span> <span class="keywordtype">bool</span> ok = file.open ( IO_ReadOnly ); <a name="l00105"></a>00105 <span class="preprocessor">#else</span> <a name="l00106"></a>00106 <span class="preprocessor"></span> <span class="keywordtype">bool</span> ok = file.open ( QIODevice::ReadOnly ); <a name="l00107"></a>00107 <span class="preprocessor">#endif</span> <a name="l00108"></a>00108 <span class="preprocessor"></span> <a name="l00109"></a>00109 <span class="keywordflow">if</span> ( ! ok ) { <a name="l00110"></a>00110 file.close (); <a name="l00111"></a>00111 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70ba14d536aa4f10161dcf259ce15008a50c">OpenError</a>; <span class="comment">//</span> <a name="l00112"></a>00112 } <a name="l00113"></a>00113 ok = <a class="code" href="classhippodraw_1_1QtXmlDocument.html#a783a8fb7e0259eb3ae22885a32a9f20a" title="The DOM element wrapped by this object.">m_document</a>.<a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdomdocument.html#setContent">setContent</a> ( &file ); <a name="l00114"></a>00114 <span class="keywordflow">if</span> ( ! ok ) { <a name="l00115"></a>00115 file.close (); <a name="l00116"></a>00116 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70baa3d32cd06318a977a4371605d6a4d84c">ParseError</a>; <a name="l00117"></a>00117 } <a name="l00118"></a>00118 <a name="l00119"></a>00119 <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qfileinfo.html">QFileInfo</a> info ( file ); <a name="l00120"></a>00120 <span class="preprocessor">#if QT_VERSION < 0x040000</span> <a name="l00121"></a>00121 <span class="preprocessor"></span> <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qstring.html">QString</a> dir = info.<a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qfileinfo.html#dirPath">dirPath</a>(); <a name="l00122"></a>00122 <span class="preprocessor">#else</span> <a name="l00123"></a>00123 <span class="preprocessor"></span> <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qstring.html">QString</a> dir = info.path(); <a name="l00124"></a>00124 <span class="preprocessor">#endif</span> <a name="l00125"></a>00125 <span class="preprocessor"></span> <a class="codeRef" doxygen="qt.tag:http://doc.trolltech.com/3.3/" href="http://doc.trolltech.com/3.3/qdir.html#setCurrent">QDir::setCurrent</a> ( dir ); <a name="l00126"></a>00126 <a name="l00127"></a>00127 file.close (); <a name="l00128"></a>00128 <a name="l00129"></a>00129 <span class="keywordflow">return</span> <a class="code" href="classhippodraw_1_1XmlDocument.html#a67a0db04d321a74b7e7fcfd3f1a3f70bafdfbdf3247bd36a1f17270d5cec74c9c">Success</a>; <a name="l00130"></a>00130 } <a name="l00131"></a>00131 <a name="l00132"></a>00132 } <span class="comment">// namespace hippodraw</span> <a name="l00133"></a>00133 </pre></div></div> <hr size="1"><address style="align: right;"><small> Generated for HippoDraw Class Library by <a href="http://www.doxygen.org/index.html"> <img src="doxygen.png" alt="doxygen" align="middle" border=0> </a> </small></address> </body> </html>