Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QDomElement Class

TheQDomElement class represents one element in the DOM tree.More...

Header:#include <QDomElement>
Inherits:QDomNode

Note: All functions in this class arereentrant.

Public Functions

QDomElement()
QDomElement(const QDomElement & x)
QStringattribute(const QString & name, const QString & defValue = QString()) const
QStringattributeNS(const QString nsURI, const QString & localName, const QString & defValue = QString()) const
QDomAttrattributeNode(const QString & name)
QDomAttrattributeNodeNS(const QString & nsURI, const QString & localName)
QDomNamedNodeMapattributes() const
QDomNodeListelementsByTagName(const QString & tagname) const
QDomNodeListelementsByTagNameNS(const QString & nsURI, const QString & localName) const
boolhasAttribute(const QString & name) const
boolhasAttributeNS(const QString & nsURI, const QString & localName) const
QDomNode::NodeTypenodeType() const
voidremoveAttribute(const QString & name)
voidremoveAttributeNS(const QString & nsURI, const QString & localName)
QDomAttrremoveAttributeNode(const QDomAttr & oldAttr)
voidsetAttribute(const QString & name, const QString & value)
voidsetAttribute(const QString & name, int value)
voidsetAttribute(const QString & name, uint value)
voidsetAttribute(const QString & name, qlonglong value)
voidsetAttribute(const QString & name, qulonglong value)
voidsetAttribute(const QString & name, float value)
voidsetAttribute(const QString & name, double value)
voidsetAttributeNS(const QString nsURI, const QString & qName, const QString & value)
voidsetAttributeNS(const QString nsURI, const QString & qName, int value)
voidsetAttributeNS(const QString nsURI, const QString & qName, uint value)
voidsetAttributeNS(const QString nsURI, const QString & qName, qlonglong value)
voidsetAttributeNS(const QString nsURI, const QString & qName, qulonglong value)
voidsetAttributeNS(const QString nsURI, const QString & qName, double value)
QDomAttrsetAttributeNode(const QDomAttr & newAttr)
QDomAttrsetAttributeNodeNS(const QDomAttr & newAttr)
voidsetTagName(const QString & name)
QStringtagName() const
QStringtext() const
QDomElement &operator=(const QDomElement & x)
  • 66 public functions inherited fromQDomNode

Detailed Description

TheQDomElement class represents one element in the DOM tree.

Elements have atagName() and zero or more attributes associated with them. The tag name can be changed withsetTagName().

Element attributes are represented byQDomAttr objects that can be queried using theattribute() andattributeNode() functions. You can set attributes with thesetAttribute() andsetAttributeNode() functions. Attributes can be removed withremoveAttribute(). There are namespace-aware equivalents to these functions, i.e.setAttributeNS(),setAttributeNodeNS() andremoveAttributeNS().

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

QDomElement e=//...//...QString s= e.text()

Thetext() 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 forQDomText 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 usetext() rather than usingfirstChild().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 withelementsByTagName() orelementsByTagNameNS().

To browse the elements of a dom document usefirstChildElement(),lastChildElement(),nextSiblingElement() andpreviousSiblingElement(). 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.nextSiblingElement("entry")) {// ...}

For further information about the Document Object Model seeLevel 1 andLevel 2 Core. For a more general introduction of the DOM implementation see theQDomDocument documentation.

Member Function Documentation

QDomElement::QDomElement()

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

QDomElement::QDomElement(constQDomElement & x)

Constructs a copy ofx.

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, usecloneNode().

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

Returns the attribute calledname. If the attribute does not existdefValue is returned.

See alsosetAttribute(),attributeNode(),setAttributeNode(), andattributeNS().

QString QDomElement::attributeNS(constQString nsURI, constQString & localName, constQString & defValue = QString()) const

Returns the attribute with the local namelocalName and the namespace URInsURI. If the attribute does not existdefValue is returned.

See alsosetAttributeNS(),attributeNodeNS(),setAttributeNodeNS(), andattribute().

QDomAttr QDomElement::attributeNode(constQString & name)

Returns theQDomAttr object that corresponds to the attribute calledname. If no such attribute exists anull attribute is returned.

See alsosetAttributeNode(),attribute(),setAttribute(), andattributeNodeNS().

QDomAttr QDomElement::attributeNodeNS(constQString & nsURI, constQString & localName)

Returns theQDomAttr object that corresponds to the attribute with the local namelocalName and the namespace URInsURI. If no such attribute exists anull attribute is returned.

See alsosetAttributeNodeNS(),setAttributeNode(),attribute(), andsetAttribute().

QDomNamedNodeMap QDomElement::attributes() const

Returns aQDomNamedNodeMap containing all this element's attributes.

See alsoattribute(),setAttribute(),attributeNode(), andsetAttributeNode().

QDomNodeList QDomElement::elementsByTagName(constQString & tagname) const

Returns aQDomNodeList containing all descendants of this element namedtagname encountered during a preorder traversal of the element subtree with this element as its root. The order of the elements in the returned list is the order they are encountered during the preorder traversal.

See alsoelementsByTagNameNS() andQDomDocument::elementsByTagName().

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

Returns aQDomNodeList containing all descendants of this element with local namelocalName and namespace URInsURI encountered during a preorder traversal of the element subtree with this element as its root. The order of the elements in the returned list is the order they are encountered during the preorder traversal.

See alsoelementsByTagName() andQDomDocument::elementsByTagNameNS().

bool QDomElement::hasAttribute(constQString & name) const

Returns true if this element has an attribute calledname; 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.

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

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

Returns true if this element has an attribute with the local namelocalName and the namespace URInsURI; otherwise returns false.

QDomNode::NodeType QDomElement::nodeType() const

ReturnsElementNode.

void QDomElement::removeAttribute(constQString & name)

Removes the attribute called namename from this element.

See alsosetAttribute(),attribute(), andremoveAttributeNS().

void QDomElement::removeAttributeNS(constQString & nsURI, constQString & localName)

Removes the attribute with the local namelocalName and the namespace URInsURI from this element.

See alsosetAttributeNS(),attributeNS(), andremoveAttribute().

QDomAttr QDomElement::removeAttributeNode(constQDomAttr & oldAttr)

Removes the attributeoldAttr from the element and returns it.

See alsoattributeNode() andsetAttributeNode().

void QDomElement::setAttribute(constQString & name, constQString & value)

Adds an attribute calledname with valuevalue. If an attribute with the same name exists, its value is replaced byvalue.

See alsoattribute(),setAttributeNode(), andsetAttributeNS().

void QDomElement::setAttribute(constQString & name,int value)

This is an overloaded function.

The number is formatted according to the current locale.

void QDomElement::setAttribute(constQString & name,uint value)

This is an overloaded function.

The number is formatted according to the current locale.

void QDomElement::setAttribute(constQString & name,qlonglong value)

This is an overloaded function.

The number is formatted according to the current locale.

void QDomElement::setAttribute(constQString & name,qulonglong value)

This is an overloaded function.

The number is formatted according to the current locale.

void QDomElement::setAttribute(constQString & name,float value)

This is an overloaded function.

The number is formatted according to the current locale.

void QDomElement::setAttribute(constQString & name,double value)

This is an overloaded function.

The number is formatted according to the current locale.

void QDomElement::setAttributeNS(constQString nsURI, constQString & qName, constQString & value)

Adds an attribute with the qualified nameqName and the namespace URInsURI with the valuevalue. If an attribute with the same local name and namespace URI exists, its prefix is replaced by the prefix ofqName and its value is repaced byvalue.

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

See alsoattributeNS(),setAttributeNodeNS(), andsetAttribute().

void QDomElement::setAttributeNS(constQString nsURI, constQString & qName,int value)

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

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

This is an overloaded function.

QDomAttr QDomElement::setAttributeNode(constQDomAttr & newAttr)

Adds the attributenewAttr to this element.

If the element has another attribute that has the same name asnewAttr, this function replaces that attribute and returns it; otherwise the function returns anull attribute.

See alsoattributeNode(),setAttribute(), andsetAttributeNodeNS().

QDomAttr QDomElement::setAttributeNodeNS(constQDomAttr & newAttr)

Adds the attributenewAttr to this element.

If the element has another attribute that has the same local name and namespace URI asnewAttr, this function replaces that attribute and returns it; otherwise the function returns anull attribute.

See alsoattributeNodeNS(),setAttributeNS(), andsetAttributeNode().

void QDomElement::setTagName(constQString & name)

Sets this element's tag name toname.

See alsotagName().

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 alsosetTagName().

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 theQDomElement for the<h1> tag, will return the following text:

HelloQt<xml is cool>

Comments are ignored by this function. It only evaluatesQDomText andQDomCDATASection objects.

QDomElement & QDomElement::operator=(constQDomElement & x)

Assignsx 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, usecloneNode().

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp