Viadeo Twitter Google Bookmarks ! Facebook Digg del.icio.us MySpace Yahoo MyWeb Blinklist Netvouz Reddit Simpy StumbleUpon Bookmarks Windows Live Favorites 
Logo Documentation Qt ·  Page d'accueil  ·  Tous les espaces de nom  ·  Toutes les classes  ·  Classes principales  ·  Annotées  ·  Classes groupées  ·  Modules  ·  Fonctions  · 

QDomElement Class Reference
[QtXml module]

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

 #include <QDomElement>

Inherits QDomNode.

Note: All the functions in this class are reentrant.

Public Functions

  • 66 public functions inherited from QDomNode

Detailed Description

The QDomElement 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 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 Level 1 and Level 2 Core. For a more general introduction of the DOM implementation see the QDomDocument documentation.


Member Function Documentation

QDomElement::QDomElement ()

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

QDomElement::QDomElement ( const QDomElement & 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().

QString QDomElement::attribute ( const QString & name, const QString & defValue = QString() ) const

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

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

QString QDomElement::attributeNS ( const QString nsURI, const QString & localName, const QString & defValue = QString() ) 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().

QDomAttr QDomElement::attributeNode ( const QString & name )

Returns the QDomAttr 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().

QDomAttr QDomElement::attributeNodeNS ( const QString & nsURI, const QString & localName )

Returns the QDomAttr 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 setAttributeNodeNS(), setAttributeNode(), attribute(), and setAttribute().

QDomNamedNodeMap QDomElement::attributes () const

Returns a QDomNamedNodeMap containing all this element's attributes.

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

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

Returns a QDomNodeList 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 QDomDocument::elementsByTagName().

QDomNodeList QDomElement::elementsByTagNameNS ( const QString & nsURI, const QString & localName ) const

Returns a QDomNodeList 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 QDomDocument::elementsByTagNameNS().

bool QDomElement::hasAttribute ( const QString & name ) const

Returns true if this element has an attribute called name; otherwise returns false.

Note: This function does not take the presence of namespaces into account. As a result, the specified name will be tested against fully-qualified attribute names that include any namespace prefixes that may be present.

Use hasAttributeNS() to explicitly test for attributes with specific namespaces and names.

bool QDomElement::hasAttributeNS ( const QString & nsURI, const QString & localName ) const

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

QDomNode::NodeType QDomElement::nodeType () const

Returns ElementNode.

void QDomElement::removeAttribute ( const QString & name )

Removes the attribute called name name from this element.

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

void QDomElement::removeAttributeNS ( const QString & nsURI, const QString & localName )

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

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

QDomAttr QDomElement::removeAttributeNode ( const QDomAttr & oldAttr )

Removes the attribute oldAttr from the element and returns it.

See also attributeNode() and setAttributeNode().

void QDomElement::setAttribute ( const QString & name, const QString & 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 QDomElement::setAttribute ( const QString & name, int value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttribute ( const QString & name, uint value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttribute ( const QString & name, qlonglong value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttribute ( const QString & name, qulonglong value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttribute ( const QString & name, float value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttribute ( const QString & name, double value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, const QString & 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 QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, int value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, uint value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, qlonglong value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, qulonglong value )

This is an overloaded member function, provided for convenience.

void QDomElement::setAttributeNS ( const QString nsURI, const QString & qName, double value )

This is an overloaded member function, provided for convenience.

QDomAttr QDomElement::setAttributeNode ( const QDomAttr & 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().

QDomAttr QDomElement::setAttributeNodeNS ( const QDomAttr & 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 QDomElement::setTagName ( const QString & name )

Sets this element's tag name to name.

See also tagName().

QString QDomElement::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().

QString QDomElement::text () const

Returns the element's text or an empty string.

Example:

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

The function text() of the QDomElement for the <h1> tag, will return the following text:

 Hello Qt &lt;xml is cool&gt;

Comments are ignored by this function. It only evaluates QDomText and QDomCDATASection objects.

QDomElement & QDomElement::operator= ( const QDomElement & 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().

Publicité

Best Of

Actualités les plus lues

Semaine
Mois
Année
  1. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  2. Pourquoi les programmeurs sont-ils moins payés que les gestionnaires de programmes ? Manquent-ils de pouvoir de négociation ? 53
  3. «Le projet de loi des droits du développeur» : quelles conditions doivent remplir les entreprises pour que le développeur puisse réussir ? 79
  4. Les développeurs détestent-ils les antivirus ? Un programmeur manifeste sa haine envers ces solutions de sécurité 28
  5. Qt Commercial : Digia organise un webinar gratuit le 27 mars sur la conception d'interfaces utilisateur et d'applications avec le framework 0
  6. Quelles nouveautés de C++11 Visual C++ doit-il rapidement intégrer ? Donnez-nous votre avis 10
  7. 2017 : un quinquennat pour une nouvelle version du C++ ? Possible, selon Herb Sutter 11
Page suivante
  1. Linus Torvalds : le "C++ est un langage horrible", en justifiant le choix du C pour le système de gestion de version Git 100
  2. Comment prendre en compte l'utilisateur dans vos applications ? Pour un développeur, « 90 % des utilisateurs sont des idiots » 229
  3. Quel est LE livre que tout développeur doit lire absolument ? Celui qui vous a le plus marqué et inspiré 96
  4. Apple cède et s'engage à payer des droits à Nokia, le conflit des brevets entre les deux firmes s'achève 158
  5. Nokia porte à nouveau plainte contre Apple pour violation de sept nouveaux brevets 158
  6. « Quelque chose ne va vraiment pas avec les développeurs "modernes" », un développeur à "l'ancienne" critique la multiplication des bibliothèques 102
  7. Quel est le code dont vous êtes le plus fier ? Pourquoi l'avez-vous écrit ? Et pourquoi vous a-t-il donné autant de satisfaction ? 83
Page suivante

Le blog Digia au hasard

Logo

Créer des applications avec un style Metro avec Qt, exemples en QML et C++, un article de Digia Qt traduit par Thibaut Cuvelier

Le blog Digia est l'endroit privilégié pour la communication sur l'édition commerciale de Qt, où des réponses publiques sont apportées aux questions les plus posées au support. Lire l'article.

Communauté

Ressources

Liens utiles

Contact

  • Vous souhaitez rejoindre la rédaction ou proposer un tutoriel, une traduction, une question... ? Postez dans le forum Contribuez ou contactez-nous par MP ou par email (voir en bas de page).

Qt dans le magazine

Cette page est une traduction d'une page de la documentation de Qt, écrite par Nokia Corporation and/or its subsidiary(-ies). Les éventuels problèmes résultant d'une mauvaise traduction ne sont pas imputables à Nokia. Qt 4.3
Copyright © 2012 Developpez LLC. Tous droits réservés Developpez LLC. Aucune reproduction, même partielle, ne peut être faite de ce site et de l'ensemble de son contenu : textes, documents et images sans l'autorisation expresse de Developpez LLC. Sinon, vous encourez selon la loi jusqu'à 3 ans de prison et jusqu'à 300 000 E de dommages et intérêts. Cette page est déposée à la SACD.
Vous avez déniché une erreur ? Un bug ? Une redirection cassée ? Ou tout autre problème, quel qu'il soit ? Ou bien vous désirez participer à ce projet de traduction ? N'hésitez pas à nous contacter ou par MP !
 
 
 
 
Partenaires

Hébergement Web