QDomDocument(3qt)

NAME
QDomDocument - The representation of an XML document

#include <qdom.h>

Inherits QDomNode.

  Public Members
QDomDocument ()
QDomDocument ( const QString & name )
QDomDocument ( const QDomDocument & x )
QDomDocument& operator= ( const QDomDocument & )
~QDomDocument ()
bool setContent ( const QCString & text )
bool setContent ( const QByteArray & text )
bool setContent ( const QString & text )
bool setContent ( QIODevice * dev )
QDomDocumentType doctype () const
QDomImplementation implementation () const
QDomElement documentElement () const
QDomElement createElement ( const QString & tagName )
QDomDocumentFragment createDocumentFragment ()
QDomText createTextNode ( const QString & data )
QDomComment createComment ( const QString & data )
QDomCDATASection createCDATASection ( const QString & data )
QDomProcessingInstruction createProcessingInstruction ( const QString & target, const QString & data )
QDomAttr createAttribute ( const QString & name )
QDomEntityReference createEntityReference ( const QString & name )
QDomNodeList elementsByTagName ( const QString & tagname ) const
virtual QDomNode::NodeType nodeType () const
virtual bool isDocument () const
QString toString () const
QCString toCString () const

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.

SEE ALSO
http://doc.trolltech.com/qdomdocument.html http://www.trolltech.com/faq/tech.html

COPYRIGHT
Copyright 1992-2001 Trolltech AS, http://www.trolltech.com. See the license file included in the distribution for a complete license statement.

AUTHOR
Generated automatically from the source code.

BUGS
If you find a bug in Qt, please report it as described in http://doc.trolltech.com/bughowto.html. Good bug reports make our job much simpler. Thank you.

In case of content or formattting problems with this manual page, please report them to qt-bugs@trolltech.com. Please include the name of the manual page (qdomdocument.3) and the Qt version (2.3.2).