![]() ![]() |
The QDomDocument class is the representation of an XML document. More...
#include <qdom.h>
Inherits QDomNode.
The Document
interface 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
interface also contains the factory
methods needed to create these objects. The Node
objects created have a ownerDocument
attribute 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 methods provided in this class. Using the default constructors of the QDom classes will only result in null 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"); doc.setContent(f); // 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 << n.name() << 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"); doc.append( 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 a null document.
creates a document with name name.
Copy constructor.
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 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 outermost element. This should usually be the Returns a QDomNodeList, that contains all elements in the document
with the tag name tagname.
Returns a QDomImplementation object.
Returns TRUE.
Reimplemented from QDomNode.
Returns QDomNode::DocumentNode.
Reimplemented from QDomNode.
Assignment operator.
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.QDomNodeList QDomDocument::elementsByTagName ( const QString & tagname ) const
QDomImplementation QDomDocument::implementation () const
bool QDomDocument::isDocument () const
[virtual]
QDomNode::NodeType QDomDocument::nodeType() const
[virtual]
QDomDocument& QDomDocument::operator= ( const QDomDocument & x )
bool QDomDocument::setContent ( const QString & text )
bool QDomDocument::setContent ( QIODevice * dev )
bool QDomDocument::setContent ( const QByteArray & buffer )
bool QDomDocument::setContent ( const QCString & buffer )
QCString QDomDocument::toCString () const
QString QDomDocument::toString () const
Copyright İ 2000 Trolltech Trademarks