📄 qdomdocument.html
字号:
docElem.<a href="qdomnode.html#appendChild">appendChild</a>( elem ); </pre> <p> Once <tt>doc</tt> and <tt>elem</tt> go out of scope, the whole internal tree representingthe XML document will get deleted.<p> To create a document using DOM use code like this:<pre> QDomDocument doc( "MyML" ); <a href="qdomelement.html">QDomElement</a> root = doc.<a href="#createElement">createElement</a>( "MyML" ); doc.<a href="qdomnode.html#appendChild">appendChild</a>( root ); <a href="qdomelement.html">QDomElement</a> tag = doc.<a href="#createElement">createElement</a>( "Greeting" ); root.<a href="qdomnode.html#appendChild">appendChild</a>( tag ); <a href="qdomtext.html">QDomText</a> t = doc.<a href="#createTextNode">createTextNode</a>( "Hello World" ); tag.<a href="qdomnode.html#appendChild">appendChild</a>( t ); <a href="qstring.html">QString</a> xml = doc.<a href="#toString">toString</a>(); </pre> <p> For further information about the Document Object Model see<a href="http://www.w3.org/TR/REC-DOM-Level-1/">http://www.w3.org/TR/REC-DOM-Level-1/</a> and<a href="http://www.w3.org/TR/DOM-Level-2-Core/">http://www.w3.org/TR/DOM-Level-2-Core/</a>.For a more general introduction of the DOM implementation see theQDomDocument documentation.<p>See also <a href="xml-tools.html">XML</a>.<hr><h2>Member Function Documentation</h2><h3 class=fn><a name="QDomDocument"></a>QDomDocument::QDomDocument ()</h3>Constructs an empty document.<h3 class=fn><a name="QDomDocument-2"></a>QDomDocument::QDomDocument ( const <a href="qstring.html">QString</a> & name )</h3>Creates a document and sets the name of the document type to <em>name</em>.<h3 class=fn><a name="QDomDocument-3"></a>QDomDocument::QDomDocument ( const <a href="qdomdocumenttype.html">QDomDocumentType</a> & doctype )</h3>Creates a document with the document type <em>doctype</em>.<p> <p>See also <a href="qdomimplementation.html#createDocumentType">QDomImplementation::createDocumentType</a>().<h3 class=fn><a name="QDomDocument-4"></a>QDomDocument::QDomDocument ( const <a href="qdomdocument.html">QDomDocument</a> & x )</h3>Constructs a copy of <em>x</em>.<p> The data of the copy is shared (shallow copy): modifying one node will alsochange the other. If you want to make a <a href="shclass.html#deep-copy">deep copy</a>, use <a href="qdomnode.html#cloneNode">cloneNode</a>().<h3 class=fn><a name="~QDomDocument"></a>QDomDocument::~QDomDocument ()</h3>Destroys the object and frees its resources.<h3 class=fn><a href="qdomattr.html">QDomAttr</a> <a name="createAttribute"></a>QDomDocument::createAttribute ( const <a href="qstring.html">QString</a> & name )</h3>Creates a new attribute called <em>name</em> that can be inserted into anelement, e.g. using <a href="qdomelement.html#setAttributeNode">QDomElement::setAttributeNode</a>().<p> <p>See also <a href="#createAttributeNS">createAttributeNS</a>().<h3 class=fn><a href="qdomattr.html">QDomAttr</a> <a name="createAttributeNS"></a>QDomDocument::createAttributeNS ( const <a href="qstring.html">QString</a> & nsURI, const <a href="qstring.html">QString</a> & qName )</h3>Creates a new attribute with namespace support that can be inserted into anelement. The name of the attribute is <em>qName</em> and the namespace URIis <em>nsURI</em>. This function also sets <a href="qdomnode.html#prefix">QDomNode::prefix</a>() and<a href="qdomnode.html#localName">QDomNode::localName</a>() to appropriate values (depending on <em>qName</em>).<p> <p>See also <a href="#createAttribute">createAttribute</a>().<h3 class=fn><a href="qdomcdatasection.html">QDomCDATASection</a> <a name="createCDATASection"></a>QDomDocument::createCDATASection ( const <a href="qstring.html">QString</a> & value )</h3>Creates a new CDATA section for the string <em>value</em> that can be inserted intothe document, e.g. using <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>().<p> <p>See also <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(), <a href="qdomnode.html#insertBefore">QDomNode::insertBefore</a>() and <a href="qdomnode.html#insertAfter">QDomNode::insertAfter</a>().<h3 class=fn><a href="qdomcomment.html">QDomComment</a> <a name="createComment"></a>QDomDocument::createComment ( const <a href="qstring.html">QString</a> & value )</h3>Creates a new comment for the string <em>value</em> that can be inserted into thedocument, e.g. using <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>().<p> <p>See also <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(), <a href="qdomnode.html#insertBefore">QDomNode::insertBefore</a>() and <a href="qdomnode.html#insertAfter">QDomNode::insertAfter</a>().<h3 class=fn><a href="qdomdocumentfragment.html">QDomDocumentFragment</a> <a name="createDocumentFragment"></a>QDomDocument::createDocumentFragment ()</h3>Creates a new document fragment, that can be used to hold parts of thedocument, e.g. when doing complex manipulations of the document tree.<h3 class=fn><a href="qdomelement.html">QDomElement</a> <a name="createElement"></a>QDomDocument::createElement ( const <a href="qstring.html">QString</a> & tagName )</h3>Creates a new element called <em>tagName</em> that can be inserted into theDOM tree, e.g. using <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>().<p> <p>See also <a href="#createElementNS">createElementNS</a>(), <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(), <a href="qdomnode.html#insertBefore">QDomNode::insertBefore</a>() and <a href="qdomnode.html#insertAfter">QDomNode::insertAfter</a>().<h3 class=fn><a href="qdomelement.html">QDomElement</a> <a name="createElementNS"></a>QDomDocument::createElementNS ( const <a href="qstring.html">QString</a> & nsURI, const <a href="qstring.html">QString</a> & qName )</h3>Creates a new element with namespace support that can be inserted into theDOM tree. The name of the element is <em>qName</em> and the namespace URIis <em>nsURI</em>. This function also sets <a href="qdomnode.html#prefix">QDomNode::prefix</a>() and<a href="qdomnode.html#localName">QDomNode::localName</a>() to appropriate values (depending on <em>qName</em>).<p> <p>See also <a href="#createElement">createElement</a>().<h3 class=fn><a href="qdomentityreference.html">QDomEntityReference</a> <a name="createEntityReference"></a>QDomDocument::createEntityReference ( const <a href="qstring.html">QString</a> & name )</h3>Creates a new entity reference called <em>name</em> that can be insertedinto the document, e.g. using <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>().<p> <p>See also <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(), <a href="qdomnode.html#insertBefore">QDomNode::insertBefore</a>() and <a href="qdomnode.html#insertAfter">QDomNode::insertAfter</a>().<h3 class=fn><a href="qdomprocessinginstruction.html">QDomProcessingInstruction</a> <a name="createProcessingInstruction"></a>QDomDocument::createProcessingInstruction ( const <a href="qstring.html">QString</a> & target, const <a href="qstring.html">QString</a> & data )</h3>Creates a new processing instruction that can be inserted into the document,e.g. using <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(). This function sets the target for theprocessing instruction to <em>target</em> and the data to <em>data</em>.<p> <p>See also <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(), <a href="qdomnode.html#insertBefore">QDomNode::insertBefore</a>() and <a href="qdomnode.html#insertAfter">QDomNode::insertAfter</a>().<h3 class=fn><a href="qdomtext.html">QDomText</a> <a name="createTextNode"></a>QDomDocument::createTextNode ( const <a href="qstring.html">QString</a> & value )</h3>Creates a text node for the string <em>value</em> that can be inserted into thedocument tree, e.g. using <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>().<p> <p>See also <a href="qdomnode.html#appendChild">QDomNode::appendChild</a>(), <a href="qdomnode.html#insertBefore">QDomNode::insertBefore</a>() and <a href="qdomnode.html#insertAfter">QDomNode::insertAfter</a>().<h3 class=fn><a href="qdomdocumenttype.html">QDomDocumentType</a> <a name="doctype"></a>QDomDocument::doctype () const</h3>Returns the document type of this document.<h3 class=fn><a href="qdomelement.html">QDomElement</a> <a name="documentElement"></a>QDomDocument::documentElement () const</h3>Returns the root element of the document.<h3 class=fn><a href="qdomelement.html">QDomElement</a> <a name="elementById"></a>QDomDocument::elementById ( const <a href="qstring.html">QString</a> & elementId )</h3>Returns the element whose ID is equal to <em>elementId</em>. If no element with theID was found, this function returns a null element.<p> Since the actual version of the QDomClasses does not know which attributesare element IDs, this function returns always a null element. This may changein a future version.<h3 class=fn><a href="qdomnodelist.html">QDomNodeList</a> <a name="elementsByTagName"></a>QDomDocument::elementsByTagName ( const <a href="qstring.html">QString</a> & tagname ) const</h3>Returns a <a href="qdomnodelist.html">QDomNodeList</a>, that contains all the elements in the documentwith the name <em>tagname</em>. The order of the node list is the order they areencountered in a preorder traversal of the element tree.<p> <p>See also <a href="#elementsByTagNameNS">elementsByTagNameNS</a>() and <a href="qdomelement.html#elementsByTagName">QDomElement::elementsByTagName</a>().<h3 class=fn><a href="qdomnodelist.html">QDomNodeList</a> <a name="elementsByTagNameNS"></a>QDomDocument::elementsByTagNameNS ( const <a href="qstring.html">QString</a> & nsURI, const <a href="qstring.html">QString</a> & localName )</h3>Returns a <a href="qdomnodelist.html">QDomNodeList</a> that contains all the elements in the documentwith the local name <em>localName</em> and a namespace URI of <em>nsURI</em>. The orderof the node list, is the order they are encountered in a preorder traversalof the element tree.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -