Logo Search packages:      
Sourcecode: qt4-x11 version File versions

QDomDocument Class Reference

Inheritance diagram for QDomDocument:


List of all members.

Detailed Description

The QDomDocument class represents an XML document.


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 DOM classes that will be used most often are QDomNode, QDomDocument, QDomElement and QDomText.

The parsed XML is represented internally by a tree of objects that can be accessed using the various QDom classes. All QDom classes 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 itself are deleted.

Creation of elements, text nodes, etc. is done using the various factory functions provided in this class. Using the default constructors of the QDom classes will only result in empty objects that cannot be manipulated or inserted into the Document.

The QDomDocument class has several functions for creating document data, for example, createElement(), createTextNode(), createComment(), createCDATASection(), createProcessingInstruction(), createAttribute() and createEntityReference(). Some of these functions have versions that support namespaces, i.e. createElementNS() and createAttributeNS(). The createDocumentFragment() function is used to hold parts of the document; this is useful for manipulating for complex documents.

The entire content of the document is set with setContent(). This function parses the string it is passed as an XML document and creates the DOM tree that represents the document. The root element is available using documentElement(). The textual representation of the document can be obtained using toString().

It is possible to insert a node from another document into the document using importNode().

You can obtain a list of all the elements that have a particular tag with elementsByTagName() or with elementsByTagNameNS().

The QDom classes are typically used as follows: doc/src/snippets/code/src.xml.dom.qdom.cpp 16

Once doc and elem go out of scope, the whole internal tree representing the XML document is deleted.

To create a document using DOM use code like this: doc/src/snippets/code/src.xml.dom.qdom.cpp 17

For further information about the Document Object Model see the Document Object Model (DOM) {http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and {http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core} Specifications.

See also:
{DOM Bookmarks Example}, {Simple DOM Model Example}

Definition at line 310 of file qdom.h.

Public Types

enum  EncodingPolicy { EncodingFromDocument = 1, EncodingFromTextStream = 2 }
enum  NodeType {
  ElementNode = 1, AttributeNode = 2, TextNode = 3, CDATASectionNode = 4,
  EntityReferenceNode = 5, EntityNode = 6, ProcessingInstructionNode = 7, CommentNode = 8,
  DocumentNode = 9, DocumentTypeNode = 10, DocumentFragmentNode = 11, NotationNode = 12,
  BaseNode = 21, CharacterDataNode = 22

Public Member Functions

QDomNode appendChild (const QDomNode &newChild)
QDomNamedNodeMap attributes () const
QDomNodeList childNodes () const
void clear ()
QDomNode cloneNode (bool deep=true) const
int columnNumber () const
QDomAttr createAttribute (const QString &name)
QDomAttr createAttributeNS (const QString &nsURI, const QString &qName)
QDomCDATASection createCDATASection (const QString &data)
QDomComment createComment (const QString &data)
QDomDocumentFragment createDocumentFragment ()
QDomElement createElement (const QString &tagName)
QDomElement createElementNS (const QString &nsURI, const QString &qName)
QDomEntityReference createEntityReference (const QString &name)
QDomProcessingInstruction createProcessingInstruction (const QString &target, const QString &data)
QDomText createTextNode (const QString &data)
QDomDocumentType doctype () const
QDomElement documentElement () const
QDomElement elementById (const QString &elementId)
QDomNodeList elementsByTagName (const QString &tagname) const
QDomNodeList elementsByTagNameNS (const QString &nsURI, const QString &localName)
QDomNode firstChild () const
QDomElement firstChildElement (const QString &tagName=QString()) const
bool hasAttributes () const
bool hasChildNodes () const
QDomImplementation implementation () const
QDomNode importNode (const QDomNode &importedNode, bool deep)
QDomNode insertAfter (const QDomNode &newChild, const QDomNode &refChild)
QDomNode insertBefore (const QDomNode &newChild, const QDomNode &refChild)
bool isAttr () const
bool isCDATASection () const
bool isCharacterData () const
bool isComment () const
bool isDocument () const
bool isDocumentFragment () const
bool isDocumentType () const
bool isElement () const
bool isEntity () const
bool isEntityReference () const
bool isNotation () const
bool isNull () const
bool isProcessingInstruction () const
bool isSupported (const QString &feature, const QString &version) const
bool isText () const
QDomNode lastChild () const
QDomElement lastChildElement (const QString &tagName=QString()) const
int lineNumber () const
QString localName () const
QDomNode namedItem (const QString &name) const
QString namespaceURI () const
QDomNode nextSibling () const
QDomElement nextSiblingElement (const QString &taName=QString()) const
QString nodeName () const
QDomNode::NodeType nodeType () const
QString nodeValue () const
void normalize ()
bool operator!= (const QDomNode &) const
QDomDocumentoperator= (const QDomDocument &)
bool operator== (const QDomNode &) const
QDomDocument ownerDocument () const
QDomNode parentNode () const
QString prefix () const
QDomNode previousSibling () const
QDomElement previousSiblingElement (const QString &tagName=QString()) const
 QDomDocument (const QDomDocument &x)
 QDomDocument (const QDomDocumentType &doctype)
 QDomDocument (const QString &name)
 QDomDocument ()
QDomNode removeChild (const QDomNode &oldChild)
QDomNode replaceChild (const QDomNode &newChild, const QDomNode &oldChild)
void save (QTextStream &, int, EncodingPolicy) const
void save (QTextStream &, int) const
bool setContent (QXmlInputSource *source, QXmlReader *reader, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
bool setContent (QIODevice *dev, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
bool setContent (const QString &text, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
bool setContent (const QByteArray &text, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
bool setContent (QIODevice *dev, bool namespaceProcessing, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
bool setContent (const QString &text, bool namespaceProcessing, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
bool setContent (const QByteArray &text, bool namespaceProcessing, QString *errorMsg=0, int *errorLine=0, int *errorColumn=0)
void setNodeValue (const QString &)
void setPrefix (const QString &pre)
QDomAttr toAttr () const
QByteArray toByteArray (int=1) const
QDomCDATASection toCDATASection () const
QDomCharacterData toCharacterData () const
QDomComment toComment () const
QDomDocument toDocument () const
QDomDocumentFragment toDocumentFragment () const
QDomDocumentType toDocumentType () const
QDomElement toElement () const
QDomEntity toEntity () const
QDomEntityReference toEntityReference () const
QDomNotation toNotation () const
QDomProcessingInstruction toProcessingInstruction () const
QString toString (int=1) const
QDomText toText () const
 ~QDomDocument ()

Protected Attributes

QDomNodePrivate * impl

Private Member Functions

 QDomDocument (QDomDocumentPrivate *)


class QDomNode

Related Functions

(Note that these are not member functions.)

QTextStreamoperator<< (QTextStream &str, const QDomNode &node)

The documentation for this class was generated from the following files:

Generated by  Doxygen 1.6.0   Back to index