'\" t .TH TQDomDocument 3qt "2 February 2007" "Trolltech AS" \" -*- nroff -*- .\" Copyright 1992-2007 Trolltech ASA. All rights reserved. See the .\" license file included in the distribution for a complete license .\" statement. .\" .ad l .nh .SH NAME TQDomDocument \- Represents an XML document .SH SYNOPSIS All the functions in this class are reentrant when TQt is built with thread support.

.PP \fC#include \fR .PP Inherits TQDomNode. .PP .SS "Public Members" .in +1c .ti -1c .BI "\fBTQDomDocument\fR ()" .br .ti -1c .BI "explicit \fBTQDomDocument\fR ( const TQString & name )" .br .ti -1c .BI "explicit \fBTQDomDocument\fR ( const TQDomDocumentType & doctype )" .br .ti -1c .BI "\fBTQDomDocument\fR ( const TQDomDocument & x )" .br .ti -1c .BI "TQDomDocument & \fBoperator=\fR ( const TQDomDocument & x )" .br .ti -1c .BI "\fB~TQDomDocument\fR ()" .br .ti -1c .BI "TQDomElement \fBcreateElement\fR ( const TQString & tagName )" .br .ti -1c .BI "TQDomDocumentFragment \fBcreateDocumentFragment\fR ()" .br .ti -1c .BI "TQDomText \fBcreateTextNode\fR ( const TQString & value )" .br .ti -1c .BI "TQDomComment \fBcreateComment\fR ( const TQString & value )" .br .ti -1c .BI "TQDomCDATASection \fBcreateCDATASection\fR ( const TQString & value )" .br .ti -1c .BI "TQDomProcessingInstruction \fBcreateProcessingInstruction\fR ( const TQString & target, const TQString & data )" .br .ti -1c .BI "TQDomAttr \fBcreateAttribute\fR ( const TQString & name )" .br .ti -1c .BI "TQDomEntityReference \fBcreateEntityReference\fR ( const TQString & name )" .br .ti -1c .BI "TQDomNodeList \fBelementsByTagName\fR ( const TQString & tagname ) const" .br .ti -1c .BI "TQDomNode \fBimportNode\fR ( const TQDomNode & importedNode, bool deep )" .br .ti -1c .BI "TQDomElement \fBcreateElementNS\fR ( const TQString & nsURI, const TQString & qName )" .br .ti -1c .BI "TQDomAttr \fBcreateAttributeNS\fR ( const TQString & nsURI, const TQString & qName )" .br .ti -1c .BI "TQDomNodeList \fBelementsByTagNameNS\fR ( const TQString & nsURI, const TQString & localName )" .br .ti -1c .BI "TQDomElement \fBelementById\fR ( const TQString & elementId )" .br .ti -1c .BI "TQDomDocumentType \fBdoctype\fR () const" .br .ti -1c .BI "TQDomImplementation \fBimplementation\fR () const" .br .ti -1c .BI "TQDomElement \fBdocumentElement\fR () const" .br .ti -1c .BI "bool \fBsetContent\fR ( const QCString & buffer, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( const QByteArray & buffer, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( const TQString & text, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( TQIODevice * dev, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( const QCString & buffer, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( const QByteArray & buffer, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( const TQString & text, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( TQIODevice * dev, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "bool \fBsetContent\fR ( TQXmlInputSource * source, TQXmlReader * reader, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" .br .ti -1c .BI "virtual TQDomNode::NodeType \fBnodeType\fR () const" .br .ti -1c .BI "virtual bool \fBisDocument\fR () const" .br .ti -1c .BI "TQString \fBtoString\fR () const" .br .ti -1c .BI "TQString \fBtoString\fR ( int indent ) const" .br .ti -1c .BI "QCString \fBtoCString\fR () const" .br .ti -1c .BI "QCString \fBtoCString\fR ( int indent ) const" .br .in -1c .SH DESCRIPTION The TQDomDocument class represents an XML document. .PP The TQDomDocument 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 TQDomNode, TQDomDocument, TQDomElement and TQDomText. .PP The parsed XML is represented internally by a tree of objects that can be accessed using the various TQDom classes. All TQDom classes only \fIreference\fR objects in the internal tree. The internal objects in the DOM tree will get deleted once the last TQDom object referencing them and the TQDomDocument 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 TQDom classes will only result in empty objects that cannot be manipulated or inserted into the Document. .PP The TQDomDocument 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 TQDom classes are typically used as follows: .PP .nf .br TQDomDocument 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 TQDomElement docElem = doc.documentElement(); .br .br TQDomNode n = docElem.firstChild(); .br while( !n.isNull() ) { .br TQDomElement 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 TQDomElement 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 TQDomDocument doc( "MyML" ); .br TQDomElement root = doc.createElement( "MyML" ); .br doc.appendChild( root ); .br .br TQDomElement tag = doc.createElement( "Greeting" ); .br root.appendChild( tag ); .br .br TQDomText t = doc.createTextNode( "Hello World" ); .br tag.appendChild( t ); .br .br TQString 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 TQDomDocument documentation. .PP See also XML. .SH MEMBER FUNCTION DOCUMENTATION .SH "TQDomDocument::TQDomDocument ()" Constructs an empty document. .SH "explicit TQDomDocument::TQDomDocument ( const TQString & name )" Creates a document and sets the name of the document type to \fIname\fR. .SH "explicit TQDomDocument::TQDomDocument ( const TQDomDocumentType & doctype )" Creates a document with the document type \fIdoctype\fR. .PP See also TQDomImplementation::createDocumentType(). .SH "TQDomDocument::TQDomDocument ( const TQDomDocument & x )" Constructs a copy of \fIx\fR. .PP The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode(). .SH "TQDomDocument::~TQDomDocument ()" Destroys the object and frees its resources. .SH "TQDomAttr TQDomDocument::createAttribute ( const TQString & name )" Creates a new attribute called \fIname\fR that can be inserted into an element, e.g. using TQDomElement::setAttributeNode(). .PP See also createAttributeNS(). .SH "TQDomAttr TQDomDocument::createAttributeNS ( const TQString & nsURI, const TQString & qName )" 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 TQDomNode::prefix() and TQDomNode::localName() to appropriate values (depending on \fIqName\fR). .PP See also createAttribute(). .SH "TQDomCDATASection TQDomDocument::createCDATASection ( const TQString & value )" Creates a new CDATA section for the string \fIvalue\fR that can be inserted into the document, e.g. using TQDomNode::appendChild(). .PP See also TQDomNode::appendChild(), TQDomNode::insertBefore(), and TQDomNode::insertAfter(). .SH "TQDomComment TQDomDocument::createComment ( const TQString & value )" Creates a new comment for the string \fIvalue\fR that can be inserted into the document, e.g. using TQDomNode::appendChild(). .PP See also TQDomNode::appendChild(), TQDomNode::insertBefore(), and TQDomNode::insertAfter(). .SH "TQDomDocumentFragment TQDomDocument::createDocumentFragment ()" Creates a new document fragment, that can be used to hold parts of the document, e.g. when doing complex manipulations of the document tree. .SH "TQDomElement TQDomDocument::createElement ( const TQString & tagName )" Creates a new element called \fItagName\fR that can be inserted into the DOM tree, e.g. using TQDomNode::appendChild(). .PP See also createElementNS(), TQDomNode::appendChild(), TQDomNode::insertBefore(), and TQDomNode::insertAfter(). .SH "TQDomElement TQDomDocument::createElementNS ( const TQString & nsURI, const TQString & qName )" 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 TQDomNode::prefix() and TQDomNode::localName() to appropriate values (depending on \fIqName\fR). .PP See also createElement(). .SH "TQDomEntityReference TQDomDocument::createEntityReference ( const TQString & name )" Creates a new entity reference called \fIname\fR that can be inserted into the document, e.g. using TQDomNode::appendChild(). .PP See also TQDomNode::appendChild(), TQDomNode::insertBefore(), and TQDomNode::insertAfter(). .SH "TQDomProcessingInstruction TQDomDocument::createProcessingInstruction ( const TQString & target, const TQString & data )" Creates a new processing instruction that can be inserted into the document, e.g. using TQDomNode::appendChild(). This function sets the target for the processing instruction to \fItarget\fR and the data to \fIdata\fR. .PP See also TQDomNode::appendChild(), TQDomNode::insertBefore(), and TQDomNode::insertAfter(). .SH "TQDomText TQDomDocument::createTextNode ( const TQString & value )" Creates a text node for the string \fIvalue\fR that can be inserted into the document tree, e.g. using TQDomNode::appendChild(). .PP \fBWarning:\fR All characters within an XML document must be in the range: .PP #x9 | #xA | #xD | [#x20-#xD7FF] | [#xE000-#xFFFD] | [#x10000-#x10FFFF] .PP 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 TQDomNode::appendChild(), TQDomNode::insertBefore(), and TQDomNode::insertAfter(). .SH "TQDomDocumentType TQDomDocument::doctype () const" Returns the document type of this document. .SH "TQDomElement TQDomDocument::documentElement () const" Returns the root element of the document. .SH "TQDomElement TQDomDocument::elementById ( const TQString & elementId )" Returns the element whose ID is equal to \fIelementId\fR. If no element with the ID was found, this function returns a null element. .PP Since the TQDomClasses do not know which attributes are element IDs, this function returns always a null element. This may change in a future version. .SH "TQDomNodeList TQDomDocument::elementsByTagName ( const TQString & tagname ) const" Returns a TQDomNodeList, 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 TQDomElement::elementsByTagName(). .SH "TQDomNodeList TQDomDocument::elementsByTagNameNS ( const TQString & nsURI, const TQString & localName )" Returns a TQDomNodeList 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 TQDomElement::elementsByTagNameNS(). .SH "TQDomImplementation TQDomDocument::implementation () const" Returns a TQDomImplementation object. .SH "TQDomNode TQDomDocument::importNode ( const TQDomNode & importedNode, bool deep )" 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 TQDomDocument and TQDomDocumentType 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 TQDomAttr and TQDomEntityReference nodes, since the descendents of TQDomAttr nodes are always imported and those of TQDomEntityReference nodes are never imported. .PP The behavior of this function is slightly different depending on the node types:
.nf .TS l - l. Node Type Behaviour TQDomAttr 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. TQDomDocument Document nodes cannot be imported. TQDomDocumentFragment If \fIdeep\fR is TRUE, this function imports the whole document fragment; otherwise it only generates an empty document fragment. TQDomDocumentType Document type nodes cannot be imported. TQDomElement Attributes for which TQDomAttr::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). TQDomEntity 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. TQDomEntityReference Descendents of entity reference nodes are never imported: \fIdeep\fR has no effect. TQDomNotation 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. TQDomProcessingInstruction The target and value of the processing instruction is copied to the new node. TQDomText The text is copied to the new node. TQDomCDATASection The text is copied to the new node. TQDomComment .TE .fi
.PP See also TQDomElement::setAttribute(), TQDomNode::insertBefore(), TQDomNode::insertAfter(), TQDomNode::replaceChild(), TQDomNode::removeChild(), and TQDomNode::appendChild(). .SH "bool TQDomDocument::isDocument () const\fC [virtual]\fR" Returns TRUE. .PP Reimplemented from TQDomNode. .SH "TQDomNode::NodeType TQDomDocument::nodeType () const\fC [virtual]\fR" Returns DocumentNode. .PP Reimplemented from TQDomNode. .SH "TQDomDocument & TQDomDocument::operator= ( const TQDomDocument & x )" Assigns \fIx\fR to this DOM document. .PP The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode(). .SH "bool TQDomDocument::setContent ( const QByteArray & buffer, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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. .PP 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 TQDomNode::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 TQDomNode::prefix(), TQDomNode::localName() and TQDomNode::namespaceURI() return TQString::null. .PP See also TQDomNode::namespaceURI(), TQDomNode::localName(), TQDomNode::prefix(), TQString::isNull(), and TQString::isEmpty(). .SH "bool TQDomDocument::setContent ( const QCString & buffer, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 C string \fIbuffer\fR. .PP \fBWarning:\fR This function does not try to detect the encoding: instead it assumes that the C string is UTF-8 encoded. .SH "bool TQDomDocument::setContent ( const TQString & text, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 string \fItext\fR. Since \fItext\fR is already a Unicode string, no encoding detection is done. .SH "bool TQDomDocument::setContent ( TQIODevice * dev, bool namespaceProcessing, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 IO device \fIdev\fR. .SH "bool TQDomDocument::setContent ( const QCString & buffer, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 C string \fIbuffer\fR. .PP No namespace processing is performed. .PP \fBWarning:\fR This function does not try to detect the encoding: instead it assumes that the C string is UTF-8 encoded. .SH "bool TQDomDocument::setContent ( const QByteArray & buffer, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 byte array \fIbuffer\fR. .PP No namespace processing is performed. .SH "bool TQDomDocument::setContent ( const TQString & text, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 string \fItext\fR. Since \fItext\fR is already a Unicode string, no encoding detection is performed. .PP No namespace processing is performed either. .SH "bool TQDomDocument::setContent ( TQIODevice * dev, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 IO device \fIdev\fR. .PP No namespace processing is performed. .SH "bool TQDomDocument::setContent ( TQXmlInputSource * source, TQXmlReader * reader, TQString * errorMsg = 0, int * errorLine = 0, int * errorColumn = 0 )" 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 TQXmlInputSource \fIsource\fR and parses it with the TQXmlReader \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 TQXmlSimpleReader. .SH "QCString TQDomDocument::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 TQDomDocument::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 "TQString TQDomDocument::toString () const" Converts the parsed document back to its textual representation. .PP See also toCString(). .SH "TQString TQDomDocument::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/tqdomdocument.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 TQt documentation is provided in HTML format; it is located at $TQTDIR/doc/html and can be read using TQt 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 (tqdomdocument.3qt) and the Qt version (3.3.8).