Home | All Classes | Main Classes | Annotated | Grouped Classes | Functions

TQDomElement Class Reference
[XML module]

The TQDomElement class represents one element in the DOM tree. More...

All the functions in this class are reentrant when TQt is built with thread support.

#include <ntqdom.h>

Inherits TQDomNode.

List of all member functions.

Public Members


Detailed Description

The TQDomElement class represents one element in the DOM tree.

Elements have a tagName() and zero or more attributes associated with them. The tag name can be changed with setTagName().

Element attributes are represented by TQDomAttr 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.

    TQDomElement e = //...
    //...
    TQString 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 TQDomText nodes, e.g.
    TQString text;
    TQDomElement element = doc.documentElement();
    for( TQDomNode n = element.firstChild(); !n.isNull(); n = n.nextSibling() )
    {
        TQDomText 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().

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

See also XML.


Member Function Documentation

TQDomElement::TQDomElement ()

Constructs an empty element. Use the TQDomDocument::createElement() function to construct elements with content.

TQDomElement::TQDomElement ( const TQDomElement & x )

Constructs a copy of x.

The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode().

TQDomElement::~TQDomElement ()

Destroys the object and frees its resources.

TQString TQDomElement::attribute ( const TQString & name, const TQString & defValue = TQString::null ) const

Returns the attribute called name. If the attribute does not exist defValue is returned.

See also setAttribute(), attributeNode(), setAttributeNode(), and attributeNS().

TQString TQDomElement::attributeNS ( const TQString nsURI, const TQString & localName, const TQString & defValue ) const

Returns the attribute with the local name localName and the namespace URI nsURI. If the attribute does not exist defValue is returned.

See also setAttributeNS(), attributeNodeNS(), setAttributeNodeNS(), and attribute().

TQDomAttr TQDomElement::attributeNode ( const TQString & name )

Returns the TQDomAttr object that corresponds to the attribute called name. If no such attribute exists a null attribute is returned.

See also setAttributeNode(), attribute(), setAttribute(), and attributeNodeNS().

TQDomAttr TQDomElement::attributeNodeNS ( const TQString & nsURI, const TQString & localName )

Returns the TQDomAttr object that corresponds to the attribute with the local name localName and the namespace URI nsURI. If no such attribute exists a null attribute is returned.

See also setAttributeNode(), attribute(), and setAttribute().

TQDomNamedNodeMap TQDomElement::attributes () const [virtual]

Returns a TQDomNamedNodeMap containing all this element's attributes.

See also attribute(), setAttribute(), attributeNode(), and setAttributeNode().

Reimplemented from TQDomNode.

TQDomNodeList TQDomElement::elementsByTagName ( const TQString & tagname ) const [virtual]

Returns a TQDomNodeList containing all descendent elements of this element that are called tagname. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree.

See also elementsByTagNameNS() and TQDomDocument::elementsByTagName().

TQDomNodeList TQDomElement::elementsByTagNameNS ( const TQString & nsURI, const TQString & localName ) const [virtual]

Returns a TQDomNodeList containing all the descendent elements of this element with the local name localName and the namespace URI nsURI. The order they are in the node list is the order they are encountered in a preorder traversal of the element tree.

See also elementsByTagName() and TQDomDocument::elementsByTagNameNS().

bool TQDomElement::hasAttribute ( const TQString & name ) const

Returns TRUE if this element has an attribute called name; otherwise returns FALSE.

bool TQDomElement::hasAttributeNS ( const TQString & nsURI, const TQString & localName ) const

Returns TRUE if this element has an attribute with the local name localName and the namespace URI nsURI; otherwise returns FALSE.

bool TQDomElement::isElement () const [virtual]

Returns TRUE.

Reimplemented from TQDomNode.

TQDomNode::NodeType TQDomElement::nodeType () const [virtual]

Returns ElementNode.

Reimplemented from TQDomNode.

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

Assigns x to this DOM element.

The data of the copy is shared (shallow copy): modifying one node will also change the other. If you want to make a deep copy, use cloneNode().

void TQDomElement::removeAttribute ( const TQString & name )

Removes the attribute called name name from this element.

See also setAttribute(), attribute(), and removeAttributeNS().

void TQDomElement::removeAttributeNS ( const TQString & nsURI, const TQString & localName )

Removes the attribute with the local name localName and the namespace URI nsURI from this element.

See also setAttributeNS(), attributeNS(), and removeAttribute().

TQDomAttr TQDomElement::removeAttributeNode ( const TQDomAttr & oldAttr )

Removes the attribute oldAttr from the element and returns it.

See also attributeNode() and setAttributeNode().

void TQDomElement::setAttribute ( const TQString & name, const TQString & value )

Adds an attribute called name with value value. If an attribute with the same name exists, its value is replaced by value.

See also attribute(), setAttributeNode(), and setAttributeNS().

void TQDomElement::setAttribute ( const TQString & name, int value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttribute ( const TQString & name, uint value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttribute ( const TQString & name, long value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttribute ( const TQString & name, ulong value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttribute ( const TQString & name, double value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttributeNS ( const TQString nsURI, const TQString & qName, const TQString & value )

Adds an attribute with the qualified name qName and the namespace URI nsURI with the value value. If an attribute with the same local name and namespace URI exists, its prefix is replaced by the prefix of qName and its value is repaced by value.

Although qName is the qualified name, the local name is used to decide if an existing attribute's value should be replaced.

See also attributeNS(), setAttributeNodeNS(), and setAttribute().

void TQDomElement::setAttributeNS ( const TQString nsURI, const TQString & qName, int value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttributeNS ( const TQString nsURI, const TQString & qName, uint value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttributeNS ( const TQString nsURI, const TQString & qName, long value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttributeNS ( const TQString nsURI, const TQString & qName, ulong value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

void TQDomElement::setAttributeNS ( const TQString nsURI, const TQString & qName, double value )

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

TQDomAttr TQDomElement::setAttributeNode ( const TQDomAttr & newAttr )

Adds the attribute newAttr to this element.

If the element has another attribute that has the same name as newAttr, this function replaces that attribute and returns it; otherwise the function returns a null attribute.

See also attributeNode(), setAttribute(), and setAttributeNodeNS().

TQDomAttr TQDomElement::setAttributeNodeNS ( const TQDomAttr & newAttr )

Adds the attribute newAttr to this element.

If the element has another attribute that has the same local name and namespace URI as newAttr, this function replaces that attribute and returns it; otherwise the function returns a null attribute.

See also attributeNodeNS(), setAttributeNS(), and setAttributeNode().

void TQDomElement::setTagName ( const TQString & name )

Sets this element's tag name to name.

See also tagName().

TQString TQDomElement::tagName () const

Returns the tag name of this element. For an XML element like this:
    <img src="myimg.png">
    
the tagname would return "img".

See also setTagName().

TQString TQDomElement::text () const

Returns the element's text or TQString::null.

Example:

    <h1>Hello <b>TQt</b> <![CDATA[<xml is cool>]]></h1>
    

The function text() of the TQDomElement for the <h1> tag, will return "Hello TQt <xml is cool>".

Comments are ignored by this function. It only evaluates TQDomText and TQDomCDATASection objects.


This file is part of the TQt toolkit. Copyright © 1995-2007 Trolltech. All Rights Reserved.


Copyright © 2007 TrolltechTrademarks
TQt 3.3.8