HomeHome

Classes - Annotated - Tree - Functions - Home - Structure Qte

QDomDocument Class Reference
[ XML module ]


The QDomDocument class is the representation of an XML document. More...

#include <qdom.h>

Inherits QDomNode.

List of all member functions.

Public Members


Detailed Description

The QDomDocument class is the representation of an XML document.

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/


Member Function Documentation

QDomDocument::QDomDocument ()

Constructs an empty document.

QDomDocument::QDomDocument ( const QString & name )

Creates a document with the name name.

QDomDocument::QDomDocument ( const QDomDocument & x )

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.

QDomDocument::~QDomDocument ()

Destructor.

QDomAttr QDomDocument::createAttribute ( const QString & name )

Creates a new attribute that can be inserted into an element.

QDomCDATASection QDomDocument::createCDATASection ( const QString & value )

Creates a new CDATA section that can be inserted into the document.

QDomComment QDomDocument::createComment ( const QString & value )

Creates a new comment that can be inserted into the Document.

QDomDocumentFragment QDomDocument::createDocumentFragment ()

Creates a new document fragment, that can be used to hold parts of the document, when doing complex manipulations of the document tree.

QDomElement QDomDocument::createElement ( const QString & tagName )

Creates a new element with the name tagName that can be inserted into the DOM tree.

QDomEntityReference QDomDocument::createEntityReference ( const QString & name )

Creates a new entity reference.

QDomProcessingInstruction QDomDocument::createProcessingInstruction ( const QString & target, const QString & data )

Creates a new processing instruction that can be inserted into the document.

QDomText QDomDocument::createTextNode ( const QString & value )

Creates a text node that can be inserted into the document tree.

QDomDocumentType QDomDocument::doctype () const

Returns the document type of this document.

QDomElement QDomDocument::documentElement () const

Returns the root element of the document.

QDomNodeList QDomDocument::elementsByTagName ( const QString & tagname ) const

Returns a QDomNodeList, that contains all elements in the document with the tag name tagname. The order of the node list, is the order they are encountered in a preorder traversal of the element tree.

QDomImplementation QDomDocument::implementation () const

Returns a QDomImplementation object.

bool QDomDocument::isDocument () const [virtual]

Returns TRUE.

Reimplemented from QDomNode.

QDomNode::NodeType QDomDocument::nodeType() const [virtual]

Returns DocumentNode.

Reimplemented from QDomNode.

QDomDocument& QDomDocument::operator= ( const QDomDocument & x )

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.

bool QDomDocument::setContent ( const QString & text )

This function parses the string text and sets it as the content of the document.

bool QDomDocument::setContent ( QIODevice * dev )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool QDomDocument::setContent ( const QByteArray & buffer )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

bool QDomDocument::setContent ( const QCString & buffer )

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

QCString QDomDocument::toCString () const

Converts the parsed document back to its textual representation.

QString QDomDocument::toString () const

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-2005 Trolltech, all rights reserved.


Copyright © 2005 TrolltechTrademarks
Qt version 2.3.10