Qtopia Home - Classes - Hierachy - Annotated - Functions - Licenses - Reference |
|
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/.
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.
Reimplemented from QDomNode.
Reimplemented from QDomNode.
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.
Converts the parsed document back to its textual representation.
This file is part of the Qtopia platform, copyright © 1995-2005 Trolltech, all rights reserved.
| Copyright © 2005 Trolltech | Trademarks | Qtopia version 2.2.0
|