📄 qdomdocument.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"><!-- /home/reggie/tmp/qt-3.0-reggie-5401/qt-x11-commercial-3.0.5/src/xml/qdom.cpp:5800 --><html><head><meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"><title>QDomDocument Class</title><style type="text/css"><!--h3.fn,span.fn { margin-left: 1cm; text-indent: -1cm; }a:link { color: #004faf; text-decoration: none }a:visited { color: #672967; text-decoration: none }body { background: #ffffff; color: black; }--></style></head><body><table border="0" cellpadding="0" cellspacing="0" width="100%"><tr bgcolor="#E5E5E5"><td valign=center> <a href="index.html"><font color="#004faf">Home</font></a> | <a href="classes.html"><font color="#004faf">All Classes</font></a> | <a href="mainclasses.html"><font color="#004faf">Main Classes</font></a> | <a href="annotated.html"><font color="#004faf">Annotated</font></a> | <a href="groups.html"><font color="#004faf">Grouped Classes</font></a> | <a href="functions.html"><font color="#004faf">Functions</font></a></td><td align="right" valign="center"><img src="logo32.png" align="right" width="64" height="32" border="0"></td></tr></table><h1 align=center>QDomDocument Class Reference<br><small>[<a href="xml.html">XML module</a>]</small></h1><p>The QDomDocument class represents an XML document.<a href="#details">More...</a><p><tt>#include <<a href="qdom-h.html">qdom.h</a>></tt><p>Inherits <a href="qdomnode.html">QDomNode</a>.<p><a href="qdomdocument-members.html">List of all member functions.</a><h2>Public Members</h2><ul><li><div class=fn><a href="#QDomDocument"><b>QDomDocument</b></a> ()</div></li><li><div class=fn><a href="#QDomDocument-2"><b>QDomDocument</b></a> ( const QString & name )</div></li><li><div class=fn><a href="#QDomDocument-3"><b>QDomDocument</b></a> ( const QDomDocumentType & doctype )</div></li><li><div class=fn><a href="#QDomDocument-4"><b>QDomDocument</b></a> ( const QDomDocument & x )</div></li><li><div class=fn>QDomDocument & <a href="#operator-eq"><b>operator=</b></a> ( const QDomDocument & x )</div></li><li><div class=fn><a href="#~QDomDocument"><b>~QDomDocument</b></a> ()</div></li><li><div class=fn>QDomElement <a href="#createElement"><b>createElement</b></a> ( const QString & tagName )</div></li><li><div class=fn>QDomDocumentFragment <a href="#createDocumentFragment"><b>createDocumentFragment</b></a> ()</div></li><li><div class=fn>QDomText <a href="#createTextNode"><b>createTextNode</b></a> ( const QString & value )</div></li><li><div class=fn>QDomComment <a href="#createComment"><b>createComment</b></a> ( const QString & value )</div></li><li><div class=fn>QDomCDATASection <a href="#createCDATASection"><b>createCDATASection</b></a> ( const QString & value )</div></li><li><div class=fn>QDomProcessingInstruction <a href="#createProcessingInstruction"><b>createProcessingInstruction</b></a> ( const QString & target, const QString & data )</div></li><li><div class=fn>QDomAttr <a href="#createAttribute"><b>createAttribute</b></a> ( const QString & name )</div></li><li><div class=fn>QDomEntityReference <a href="#createEntityReference"><b>createEntityReference</b></a> ( const QString & name )</div></li><li><div class=fn>QDomNodeList <a href="#elementsByTagName"><b>elementsByTagName</b></a> ( const QString & tagname ) const</div></li><li><div class=fn>QDomNode <a href="#importNode"><b>importNode</b></a> ( const QDomNode & importedNode, bool deep )</div></li><li><div class=fn>QDomElement <a href="#createElementNS"><b>createElementNS</b></a> ( const QString & nsURI, const QString & qName )</div></li><li><div class=fn>QDomAttr <a href="#createAttributeNS"><b>createAttributeNS</b></a> ( const QString & nsURI, const QString & qName )</div></li><li><div class=fn>QDomNodeList <a href="#elementsByTagNameNS"><b>elementsByTagNameNS</b></a> ( const QString & nsURI, const QString & localName )</div></li><li><div class=fn>QDomElement <a href="#elementById"><b>elementById</b></a> ( const QString & elementId )</div></li><li><div class=fn>QDomDocumentType <a href="#doctype"><b>doctype</b></a> () const</div></li><li><div class=fn>QDomImplementation <a href="#implementation"><b>implementation</b></a> () const</div></li><li><div class=fn>QDomElement <a href="#documentElement"><b>documentElement</b></a> () const</div></li><li><div class=fn>bool <a href="#setContent-2"><b>setContent</b></a> ( const QCString & buffer, bool namespaceProcessing, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent"><b>setContent</b></a> ( const QByteArray & buffer, bool namespaceProcessing, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent-3"><b>setContent</b></a> ( const QString & text, bool namespaceProcessing, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent-4"><b>setContent</b></a> ( QIODevice * dev, bool namespaceProcessing, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent-5"><b>setContent</b></a> ( const QCString & buffer, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent-6"><b>setContent</b></a> ( const QByteArray & buffer, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent-7"><b>setContent</b></a> ( const QString & text, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>bool <a href="#setContent-8"><b>setContent</b></a> ( QIODevice * dev, QString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )</div></li><li><div class=fn>virtual QDomNode::NodeType <a href="#nodeType"><b>nodeType</b></a> () const</div></li><li><div class=fn>virtual bool <a href="#isDocument"><b>isDocument</b></a> () const</div></li><li><div class=fn>QString <a href="#toString"><b>toString</b></a> () const</div></li><li><div class=fn>QCString <a href="#toCString"><b>toCString</b></a> () const</div></li></ul><hr><a name="details"></a><h2>Detailed Description</h2>The QDomDocument class represents an XML document.<p> <p> The QDomDocument class represents the entire XML document.Conceptually, it is the root of the document tree, and provides theprimary access to the document's data.<p> Since elements, text nodes, comments, processing instructions, etc.cannot exist outside the context of a document, the document classalso contains the factory functions needed to create these objects.The node objects created have an <a href="qdomnode.html#ownerDocument">ownerDocument</a>() function whichassociates them with the document within whose context they werecreated. The DOM classes that will be used most often are <a href="qdomnode.html">QDomNode</a>,QDomDocument, <a href="qdomelement.html">QDomElement</a> and <a href="qdomtext.html">QDomText</a>.<p> The parsed XML is represented internally by a tree of objects that canbe accessed using the various QDom classes. All QDom classes only <em>reference</em> objects in the internal tree. The internal objects in theDOM tree will get deleted, once the last QDom object referencing themand the QDomDocument itself are deleted.<p> Creation of elements, text nodes, etc. is done via the various factoryfunctions provided in this class. Using the default constructors ofthe QDom classes will only result in empty objects, that cannot bemanipulated or inserted into the Document.<p> The QDomDocument class has several functions for creating documentdata, for example, <a href="#createElement">createElement</a>(), <a href="#createTextNode">createTextNode</a>(), <a href="#createComment">createComment</a>(),<a href="#createCDATASection">createCDATASection</a>(), <a href="#createProcessingInstruction">createProcessingInstruction</a>(), <a href="#createAttribute">createAttribute</a>()and <a href="#createEntityReference">createEntityReference</a>(). Some of these functions have versionsthat support namespaces, i.e. <a href="#createElementNS">createElementNS</a>() and<a href="#createAttributeNS">createAttributeNS</a>(). The <a href="#createDocumentFragment">createDocumentFragment</a>() function is used tohold parts of the document, e.g. for complex documents.<p> The entire content of the document is set with <a href="#setContent">setContent</a>(). Thisfunction parses the string it is passed as an XML document and createsthe DOM tree that represents the document. The root element isavailable using <a href="#documentElement">documentElement</a>(). The textual representation of thedocument can be obtained using <a href="#toString">toString</a>().<p> It is possible to insert a node from another document into thedocument using <a href="#importNode">importNode</a>().<p> You can obtain a list of all the elements that have a particular tagwith <a href="#elementsByTagName">elementsByTagName</a>() or with <a href="#elementsByTagNameNS">elementsByTagNameNS</a>().<p> The QDom classes are typically used as follows:<pre> QDomDocument doc( "mydocument" ); <a href="qfile.html">QFile</a> f( "mydocument.xml" ); if ( !f.<a href="qfile.html#open">open</a>( <a href="qfile.html#open">IO_ReadOnly</a> ) ) return; if ( !doc.<a href="#setContent">setContent</a>( &f ) ) { f.<a href="qfile.html#close">close</a>(); return; } f.<a href="qfile.html#close">close</a>(); // print out the element names of all elements that are direct children // of the outermost element. <a href="qdomelement.html">QDomElement</a> docElem = doc.<a href="#documentElement">documentElement</a>(); <a href="qdomnode.html">QDomNode</a> n = docElem.<a href="qdomnode.html#firstChild">firstChild</a>(); while( !n.<a href="qdomnode.html#isNull">isNull</a>() ) { <a href="qdomelement.html">QDomElement</a> e = n.<a href="qdomnode.html#toElement">toElement</a>(); // try to convert the node to an element. if( !e.<a href="qdomnode.html#isNull">isNull</a>() ) { cout << e.<a href="qdomelement.html#tagName">tagName</a>() << endl; // the node really is an element. } n = n.<a href="qdomnode.html#nextSibling">nextSibling</a>(); } // Here we append a new element to the end of the document <a href="qdomelement.html">QDomElement</a> elem = doc.<a href="#createElement">createElement</a>( "img" ); elem.<a href="qdomelement.html#setAttribute">setAttribute</a>( "src", "myimage.png" );
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -