The QDomDocument class is the representation of an XML document. More...
#include <qdom.h>
Inherits QDomNode.
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.
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 parsed XML is represented internally by a tree of objects that can be accessed using the various QDom classes. All QDom classes do only reference 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 are deleted.
Creation of elements, text nodes, etc. is done via the various factory functions provided in this class. Using the default constructors of the QDom classes will only result in empty objects, that can not be manipulated or inserted into the Document.
The QDom classes are typically used as follows:
QDomDocument doc( "mydocument" ); QFile f( "mydocument.xml" ); if ( !f.open( IO_ReadOnly ) ) return; if ( !doc.setContent( &f ) ) { f.close(); return; } f.close(); // print out the element names of all elements that are a direct child // of the outermost element. QDomElement docElem = doc.documentElement(); QDomNode n = docElem.firstChild(); while( !n.isNull() ) { QDomElement e = n.toElement(); // try to convert the node to an element. if( !e.isNull() ) { // the node was really an element. cout << e.tagName() << endl; } n = n.nextSibling(); } // lets append a new element to the end of the document QDomElement elem = doc.createElement( "img" ); elem.setAttribute( "src", "myimage.png" ); docElem.appendChild( elem );
Once doc
and elem
go out of scode, the whole internal tree representing
the XML document will get deleted.
For further information about the Document Objct Model see http://www.w3.org/TR/REC-DOM-Level-1/
Constructs an empty document.
Creates a document with the name name.
Copy constructor.
The data of the copy is shared: modifying one will also change the other. If you want to make a real copy, use cloneNode() instead.
Destructor.
Creates a new attribute that can be inserted into an element.
Creates a new CDATA section that can be inserted into the document.
Creates a new comment that can be inserted into the Document.
Creates a new document fragment, that can be used to hold parts of the document, when doing complex manipulations of the document tree.
Creates a new element with the name tagName that can be inserted into the DOM tree.
Creates a new entity reference.
Creates a new processing instruction that can be inserted into the document.
Creates a text node that can be inserted into the document tree.
Returns the document type of this document.
Returns the root element of the document.
Returns a QDomNodeList, that contains all elements in the document with the tag name tagname.
Returns a QDomImplementation object.
[virtual]
Returns TRUE.
Reimplemented from QDomNode.
[virtual]
Returns DocumentNode.
Reimplemented from QDomNode.
Assignment operator.
The data of the copy is shared: modifying one will also change the other. If you want to make a real copy, use cloneNode() instead.
This function parses the string text and sets it as the content of the document.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Converts the parsed document back to its textual representation.
Converts the parsed document back to its textual representation.
Search the documentation, FAQ, qt-interest archive and more (uses
www.trolltech.com):
This file is part of the Qt toolkit, copyright © 1995-2000 Trolltech, all rights reserved.
Copyright İ 2000 Trolltech | Trademarks | Qt version 2.2.1
|