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

QDomElement Class Reference

Inheritance diagram for QDomElement:

QDomNode

List of all members.


Detailed Description

The QDomElement class represents one element in the DOM tree.

XML

Element attributes are represented by QDomAttr objects that can be queried using the attribute() and attributeNode() functions. You can set attributes with the setAttribute() and setAttributeNode() functions. Attributes can be removed with removeAttribute(). There are namespace-aware equivalents to these functions, i.e. setAttributeNS(), setAttributeNodeNS() and removeAttributeNS().

If you want to access the text of a node use text(), e.g.

    QDomElement e = //...
    //...
    QString s = e.text()
The text() function operates recursively to find the text (since not all elements contain text). If you want to find all the text in all of a node's children, iterate over the children looking for QDomText nodes, e.g.
    QString text;
    QDomElement element = doc.documentElement();
    for(QDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling())
    {
        QDomText t = n.toText();
        if (!t.isNull())
            text += t.data();
    }
Note that we attempt to convert each node to a text node and use text() rather than using firstChild().toText().data() or n.toText().data() directly on the node, because the node may not be a text element.

You can get a list of all the decendents of an element which have a specified tag name with elementsByTagName() or elementsByTagNameNS().

To browse the elements of a dom document use firstChildElement(), lastChildElement(), nextSiblingElement() and previousSiblingElement(). For example, to iterate over all child elements called "entry" in a root element called "database", you can use:

    QDomDocument doc = // ...
    QDomElement root = doc.firstChildElement("database");
    QDomElement elt = root.firstChildElement("entry");
    for (; !elt.isNull(); elt = elt.nextSiblingElelement("entry")) {
        // ...
    }

For further information about the Document Object Model see {http://www.w3.org/TR/REC-DOM-Level-1/}{Level 1} and {http://www.w3.org/TR/DOM-Level-2-Core/}{Level 2 Core}. For a more general introduction of the DOM implementation see the QDomDocument documentation.

Definition at line 475 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)
QString attribute (const QString &name, const QString &defValue=QString()) const
QDomAttr attributeNode (const QString &name)
QDomAttr attributeNodeNS (const QString &nsURI, const QString &localName)
QString attributeNS (const QString nsURI, const QString &localName, const QString &defValue=QString()) const
QDomNamedNodeMap attributes () const
QDomNodeList childNodes () const
void clear ()
QDomNode cloneNode (bool deep=true) const
int columnNumber () const
QDomNodeList elementsByTagName (const QString &tagname) const
QDomNodeList elementsByTagNameNS (const QString &nsURI, const QString &localName) const
QDomNode firstChild () const
QDomElement firstChildElement (const QString &tagName=QString()) const
bool hasAttribute (const QString &name) const
bool hasAttributeNS (const QString &nsURI, const QString &localName) const
bool hasAttributes () const
bool hasChildNodes () const
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
QDomElementoperator= (const QDomElement &)
bool operator== (const QDomNode &) const
QDomDocument ownerDocument () const
QDomNode parentNode () const
QString prefix () const
QDomNode previousSibling () const
QDomElement previousSiblingElement (const QString &tagName=QString()) const
 QDomElement (const QDomElement &x)
 QDomElement ()
void removeAttribute (const QString &name)
QDomAttr removeAttributeNode (const QDomAttr &oldAttr)
void removeAttributeNS (const QString &nsURI, const QString &localName)
QDomNode removeChild (const QDomNode &oldChild)
QDomNode replaceChild (const QDomNode &newChild, const QDomNode &oldChild)
void save (QTextStream &, int, EncodingPolicy) const
void save (QTextStream &, int) const
void setAttribute (const QString &name, double value)
void setAttribute (const QString &name, float value)
void setAttribute (const QString &name, uint value)
void setAttribute (const QString &name, int value)
void setAttribute (const QString &name, qulonglong value)
void setAttribute (const QString &name, qlonglong value)
void setAttribute (const QString &name, const QString &value)
QDomAttr setAttributeNode (const QDomAttr &newAttr)
QDomAttr setAttributeNodeNS (const QDomAttr &newAttr)
void setAttributeNS (const QString nsURI, const QString &qName, double value)
void setAttributeNS (const QString nsURI, const QString &qName, qulonglong value)
void setAttributeNS (const QString nsURI, const QString &qName, qlonglong value)
void setAttributeNS (const QString nsURI, const QString &qName, uint value)
void setAttributeNS (const QString nsURI, const QString &qName, int value)
void setAttributeNS (const QString nsURI, const QString &qName, const QString &value)
void setNodeValue (const QString &)
void setPrefix (const QString &pre)
void setTagName (const QString &name)
QString tagName () const
QString text () const
QDomAttr toAttr () 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
QDomText toText () const

Protected Attributes

QDomNodePrivate * impl

Private Member Functions

 QDomElement (QDomElementPrivate *)

Friends

class QDomAttr
class QDomDocument
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