.BI "QCString \fBtoCString\fR ( int indent ) const"
.br
.in -1c
.SH DESCRIPTION
The QDomDocument class represents an XML document.
.PP
The QDomDocument class represents the entire XML document. Conceptually, it is the root of the document tree, and provides the primary access to the document's data.
.PP
Since elements, text nodes, comments, processing instructions, etc., cannot exist outside the context of a document, the document class also contains the factory functions needed to create these objects. The node objects created have an ownerDocument() function which associates them with the document within whose context they were created. The DOM classes that will be used most often are QDomNode, QDomDocument, QDomElement and QDomText.
.PP
The parsed XML is represented internally by a tree of objects that can be accessed using the various QDom classes. All QDom classes only \fIreference\fR objects in the internal tree. The internal objects in the DOM tree will get deleted once the last QDom object referencing them and the QDomDocument itself are deleted.
.PP
Creation of elements, text nodes, etc. is done using the various factory functions provided in this class. Using the default constructors of the QDom classes will only result in empty objects that cannot be manipulated or inserted into the Document.
.PP
The QDomDocument class has several functions for creating document data, for example, createElement(), createTextNode(), createComment(), createCDATASection(), createProcessingInstruction(), createAttribute() and createEntityReference(). Some of these functions have versions that support namespaces, i.e. createElementNS() and createAttributeNS(). The createDocumentFragment() function is used to hold parts of the document; this is useful for manipulating for complex documents.
.PP
The entire content of the document is set with setContent(). This function parses the string it is passed as an XML document and creates the DOM tree that represents the document. The root element is available using documentElement(). The textual representation of the document can be obtained using toString().
.PP
It is possible to insert a node from another document into the document using importNode().
.PP
You can obtain a list of all the elements that have a particular tag with elementsByTagName() or with elementsByTagNameNS().
.PP
The QDom classes are typically used as follows:
.PP
.nf
.br
QDomDocument doc( "mydocument" );
.br
QFile file( "mydocument.xml" );
.br
if ( !file.open( IO_ReadOnly ) )
.br
return;
.br
if ( !doc.setContent( &file ) ) {
.br
file.close();
.br
return;
.br
}
.br
file.close();
.br
.br
// print out the element names of all elements that are direct children
.br
// of the outermost element.
.br
QDomElement docElem = doc.documentElement();
.br
.br
QDomNode n = docElem.firstChild();
.br
while( !n.isNull() ) {
.br
QDomElement e = n.toElement(); // try to convert the node to an element.
.br
if( !e.isNull() ) {
.br
cout << e.tagName() << endl; // the node really is an element.
.br
}
.br
n = n.nextSibling();
.br
}
.br
.br
// Here we append a new element to the end of the document
.br
QDomElement elem = doc.createElement( "img" );
.br
elem.setAttribute( "src", "myimage.png" );
.br
docElem.appendChild( elem );
.br
.fi
.PP
Once \fCdoc\fR and \fCelem\fR go out of scope, the whole internal tree representing the XML document is deleted.
.PP
To create a document using DOM use code like this:
.PP
.nf
.br
QDomDocument doc( "MyML" );
.br
QDomElement root = doc.createElement( "MyML" );
.br
doc.appendChild( root );
.br
.br
QDomElement tag = doc.createElement( "Greeting" );
.br
root.appendChild( tag );
.br
.br
QDomText t = doc.createTextNode( "Hello World" );
.br
tag.appendChild( t );
.br
.br
QString xml = doc.toString();
.br
.fi
.PP
For further information about the Document Object Model see http://www.w3.org/TR/REC-DOM-Level-1/ and http://www.w3.org/TR/DOM-Level-2-Core/. For a more general introduction of the DOM implementation see the QDomDocument documentation.
.PP
See also XML.
.SH MEMBER FUNCTION DOCUMENTATION
.SH "QDomDocument::QDomDocument ()"
Constructs an empty document.
.SH "explicit QDomDocument::QDomDocument ( const QString & name )"
Creates a document and sets the name of the document type to \fIname\fR.
Creates a new attribute with namespace support that can be inserted into an element. The name of the attribute is \fIqName\fR and the namespace URI is \fInsURI\fR. This function also sets QDomNode::prefix() and QDomNode::localName() to appropriate values (depending on \fIqName\fR).
.PP
See also createAttribute().
.SH "QDomCDATASection QDomDocument::createCDATASection ( const QString & value )"
Creates a new CDATA section for the string \fIvalue\fR that can be inserted into the document, e.g. using QDomNode::appendChild().
.PP
See also QDomNode::appendChild(), QDomNode::insertBefore(), and QDomNode::insertAfter().
.SH "QDomComment QDomDocument::createComment ( const QString & value )"
Creates a new comment for the string \fIvalue\fR that can be inserted into the document, e.g. using QDomNode::appendChild().
.PP
See also QDomNode::appendChild(), QDomNode::insertBefore(), and QDomNode::insertAfter().
Creates a new element with namespace support that can be inserted into the DOM tree. The name of the element is \fIqName\fR and the namespace URI is \fInsURI\fR. This function also sets QDomNode::prefix() and QDomNode::localName() to appropriate values (depending on \fIqName\fR).
.PP
See also createElement().
.SH "QDomEntityReference QDomDocument::createEntityReference ( const QString & name )"
Creates a new entity reference called \fIname\fR that can be inserted into the document, e.g. using QDomNode::appendChild().
.PP
See also QDomNode::appendChild(), QDomNode::insertBefore(), and QDomNode::insertAfter().
Creates a new processing instruction that can be inserted into the document, e.g. using QDomNode::appendChild(). This function sets the target for the processing instruction to \fItarget\fR and the data to \fIdata\fR.
.PP
See also QDomNode::appendChild(), QDomNode::insertBefore(), and QDomNode::insertAfter().
.SH "QDomText QDomDocument::createTextNode ( const QString & value )"
Creates a text node for the string \fIvalue\fR that can be inserted into the document tree, e.g. using QDomNode::appendChild().
.PP
\fBWarning:\fR All characters within an XML document must be in the range:
This rule also applies to characters encoded as character entities and characters in CDATA sections. If you use this function to insert characters outside of this range, the document will not be well-formed.
.PP
If you want to store binary data in an XML document you must either use your own scheme to escape illegal characters, or you must store it in an external unparsed entity.
.PP
See also QDomNode::appendChild(), QDomNode::insertBefore(), and QDomNode::insertAfter().
Returns a QDomNodeList, that contains all the elements in the document with the name \fItagname\fR. The order of the node list is the order they are encountered in a preorder traversal of the element tree.
.PP
See also elementsByTagNameNS() and QDomElement::elementsByTagName().
Returns a QDomNodeList that contains all the elements in the document with the local name \fIlocalName\fR and a namespace URI of \fInsURI\fR. The order of the node list is the order they are encountered in a preorder traversal of the element tree.
.PP
See also elementsByTagName() and QDomElement::elementsByTagNameNS().
Imports the node \fIimportedNode\fR from another document to this document. \fIimportedNode\fR remains in the original document; this function creates a copy that can be used within this document.
.PP
This function returns the imported node that belongs to this document. The returned node has no parent. It is not possible to import QDomDocument and QDomDocumentType nodes. In those cases this function returns a null node.
.PP
If \fIdeep\fR is TRUE, this function imports not only the node \fIimportedNode\fR but its whole subtree; if it is FALSE, only the \fIimportedNode\fR is imported. The argument \fIdeep\fR has no effect on QDomAttr and QDomEntityReference nodes, since the descendents of QDomAttr nodes are always imported and those of QDomEntityReference nodes are never imported.
.PP
The behavior of this function is slightly different depending on the node types: <center>.nf
.TS
l - l. Node Type Behaviour QDomAttr The owner element is set to 0 and the specified flag is set to TRUE in the generated attribute. The whole subtree of \fIimportedNode\fR is always imported for attribute nodes: \fIdeep\fR has no effect. QDomDocument Document nodes cannot be imported. QDomDocumentFragment If \fIdeep\fR is TRUE, this function imports the whole document fragment; otherwise it only generates an empty document fragment. QDomDocumentType Document type nodes cannot be imported. QDomElement Attributes for which QDomAttr::specified() is TRUE are also imported, other attributes are not imported. If \fIdeep\fR is TRUE, this function also imports the subtree of \fIimportedNode\fR; otherwise it imports only the element node (and some attributes, see above). QDomEntity Entity nodes can be imported, but at the moment there is no way to use them since the document type is read-only in DOM level 2. QDomEntityReference Descendents of entity reference nodes are never imported: \fIdeep\fR has no effect. QDomNotation Notation nodes can be imported, but at the moment there is no way to use them since the document type is read-only in DOM level 2. QDomProcessingInstruction The target and value of the processing instruction is copied to the new node. QDomText The text is copied to the new node. QDomCDATASection The text is copied to the new node. QDomComment
.TE
.fi
</center>
.PP
See also QDomElement::setAttribute(), QDomNode::insertBefore(), QDomNode::insertAfter(), QDomNode::replaceChild(), QDomNode::removeChild(), and QDomNode::appendChild().
This function parses the XML document from the byte array \fIbuffer\fR and sets it as the content of the document. It tries to detect the encoding of the document as required by the XML specification.
If \fInamespaceProcessing\fR is TRUE, the parser recognizes namespaces in the XML file and sets the prefix name, local name and namespace URI to appropriate values. If \fInamespaceProcessing\fR is FALSE, the parser does no namespace processing when it reads the XML file.
.PP
If a parse error occurs, the function returns FALSE; otherwise it returns TRUE. If a parse error occurs and \fIerrorMsg\fR, \fIerrorLine\fR and \fIerrorColumn\fR are not 0, the error message is placed in \fI*errorMsg\fR, the line number \fI*errorLine\fR and the column number in \fI*errorColumn\fR.
.PP
If \fInamespaceProcessing\fR is TRUE, the function QDomNode::prefix() returns a string for all elements and attributes. It returns an empty string if the element or attribute has no prefix.
.PP
If \fInamespaceProcessing\fR is FALSE, the functions QDomNode::prefix(), QDomNode::localName() and QDomNode::namespaceURI() return QString::null.
.PP
See also QDomNode::namespaceURI(), QDomNode::localName(), QDomNode::prefix(), QString::isNull(), and QString::isEmpty().
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This function reads the XML document from the QXmlInputSource \fIsource\fR and parses it with the QXmlReader \fIreader\fR.
.PP
This function doesn't change the features of the \fIreader\fR. If you want to use certain features for parsing you can use this function to set up the reader appropriate.
.PP
See also QXmlSimpleReader.
.SH "QCString QDomDocument::toCString () const"
Converts the parsed document back to its textual representation and returns a QCString for that is encoded in UTF-8.
.PP
See also toString().
.SH "QCString QDomDocument::toCString ( int indent ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This function uses \fIindent\fR as the amount of space to indent subelements.
.SH "QString QDomDocument::toString () const"
Converts the parsed document back to its textual representation.
.PP
See also toCString().
.SH "QString QDomDocument::toString ( int indent ) const"
This is an overloaded member function, provided for convenience. It behaves essentially like the above function.
.PP
This function uses \fIindent\fR as the amount of space to indent
subelements.
.SH "SEE ALSO"
.BR http://doc.trolltech.com/qdomdocument.html
.BR http://www.trolltech.com/faq/tech.html
.SH COPYRIGHT
Copyright 1992-2007 Trolltech ASA, http://www.trolltech.com. See the
license file included in the distribution for a complete license
statement.
.SH AUTHOR
Generated automatically from the source code.
.SH BUGS
If you find a bug in Qt, please report it as described in
.BR http://doc.trolltech.com/bughowto.html .
Good bug reports help us to help you. Thank you.
.P
The definitive Qt documentation is provided in HTML format; it is
located at $QTDIR/doc/html and can be read using Qt Assistant or with
a web browser. This man page is provided as a convenience for those
users who prefer man pages, although this format is not officially
supported by Trolltech.
.P
If you find errors in this manual page, please report them to
.BR qt-bugs@trolltech.com .
Please include the name of the manual page (qdomdocument.3qt) and the Qt