|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.trolltech.qt.QSignalEmitter
com.trolltech.qt.QtJambiObject
com.trolltech.qt.xml.QDomNode
com.trolltech.qt.xml.QDomElement
public class QDomElement
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.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class com.trolltech.qt.xml.QDomNode |
---|
QDomNode.EncodingPolicy, QDomNode.NodeType |
Nested classes/interfaces inherited from class com.trolltech.qt.QSignalEmitter |
---|
QSignalEmitter.Signal0, QSignalEmitter.Signal1, QSignalEmitter.Signal2, QSignalEmitter.Signal3, QSignalEmitter.Signal4, QSignalEmitter.Signal5, QSignalEmitter.Signal6, QSignalEmitter.Signal7, QSignalEmitter.Signal8, QSignalEmitter.Signal9 |
Constructor Summary | |
---|---|
QDomElement()
Constructs an empty element. |
|
QDomElement(QDomElement x)
Constructs a copy of x. |
Method Summary | |
---|---|
java.lang.String |
attribute(java.lang.String name)
Returns the attribute called name. |
java.lang.String |
attribute(java.lang.String name,
java.lang.String defValue)
Returns the attribute called name. |
QDomAttr |
attributeNode(java.lang.String name)
Returns the QDomAttr object that corresponds to the attribute called name. |
QDomAttr |
attributeNodeNS(java.lang.String nsURI,
java.lang.String localName)
Returns the QDomAttr object that corresponds to the attribute with the local name localName and the namespace URI nsURI. |
java.lang.String |
attributeNS(java.lang.String nsURI,
java.lang.String localName)
Returns the attribute with the local name localName and the namespace URI nsURI. |
java.lang.String |
attributeNS(java.lang.String nsURI,
java.lang.String localName,
java.lang.String defValue)
Returns the attribute with the local name localName and the namespace URI nsURI. |
QDomNamedNodeMap |
attributes()
Returns a QDomNamedNodeMap containing all this element's attributes. |
QDomElement |
clone()
This method is reimplemented for internal reasons |
QDomNodeList |
elementsByTagName(java.lang.String tagname)
Returns a QDomNodeList containing all descendants of this element named tagname encountered during a preorder traversal of the element subtree with this element as its root. |
QDomNodeList |
elementsByTagNameNS(java.lang.String nsURI,
java.lang.String localName)
Returns a QDomNodeList containing all descendants of this element with local name localName and namespace URI nsURI encountered during a preorder traversal of the element subtree with this element as its root. |
static QDomElement |
fromNativePointer(QNativePointer nativePointer)
|
boolean |
hasAttribute(java.lang.String name)
Returns true if this element has an attribute called name; otherwise returns false. |
boolean |
hasAttributeNS(java.lang.String nsURI,
java.lang.String localName)
Returns true if this element has an attribute with the local name localName and the namespace URI nsURI; otherwise returns false. |
static QNativePointer |
nativePointerArray(QDomElement[] array)
|
void |
removeAttribute(java.lang.String name)
Removes the attribute called name name from this element. |
QDomAttr |
removeAttributeNode(QDomAttr oldAttr)
Removes the attribute oldAttr from the element and returns it. |
void |
removeAttributeNS(java.lang.String nsURI,
java.lang.String localName)
Removes the attribute with the local name localName and the namespace URI nsURI from this element. |
void |
setAttribute(java.lang.String name,
double value)
This is an overloaded method provided for convenience. |
void |
setAttribute(java.lang.String name,
float value)
This is an overloaded method provided for convenience. |
void |
setAttribute(java.lang.String name,
int value)
This is an overloaded method provided for convenience. |
void |
setAttribute(java.lang.String name,
long value)
This is an overloaded method provided for convenience. |
void |
setAttribute(java.lang.String name,
java.lang.String value)
Adds an attribute called name with value value. |
QDomAttr |
setAttributeNode(QDomAttr newAttr)
Adds the attribute newAttr to this element. |
QDomAttr |
setAttributeNodeNS(QDomAttr newAttr)
Adds the attribute newAttr to this element. |
void |
setAttributeNS(java.lang.String nsURI,
java.lang.String qName,
double value)
This is an overloaded method provided for convenience. |
void |
setAttributeNS(java.lang.String nsURI,
java.lang.String qName,
int value)
This is an overloaded method provided for convenience. |
void |
setAttributeNS(java.lang.String nsURI,
java.lang.String qName,
long value)
This is an overloaded method provided for convenience. |
void |
setAttributeNS(java.lang.String nsURI,
java.lang.String qName,
java.lang.String value)
Adds an attribute with the qualified name qName and the namespace URI nsURI with the value value. |
void |
setTagName(java.lang.String name)
Sets this element's tag name to name. |
java.lang.String |
tagName()
Returns the tag name of this element. |
java.lang.String |
text()
Returns the element's text or an empty string. |
Methods inherited from class com.trolltech.qt.QtJambiObject |
---|
dispose, disposed, equals, finalize, reassignNativeResources, tr, tr, tr |
Methods inherited from class com.trolltech.qt.QSignalEmitter |
---|
blockSignals, disconnect, disconnect, signalsBlocked, signalSender, thread |
Methods inherited from class java.lang.Object |
---|
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Methods inherited from interface com.trolltech.qt.QtJambiInterface |
---|
disableGarbageCollection, nativeId, nativePointer, reenableGarbageCollection, setJavaOwnership |
Constructor Detail |
---|
public QDomElement()
QDomDocument::createElement()
function to construct elements with content.
public QDomElement(QDomElement 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()
.
Method Detail |
---|
public final java.lang.String attribute(java.lang.String name)
setAttribute()
, attributeNode()
, setAttributeNode()
, and attributeNS()
.
public final java.lang.String attribute(java.lang.String name, java.lang.String defValue)
setAttribute()
, attributeNode()
, setAttributeNode()
, and attributeNS()
.
public final java.lang.String attributeNS(java.lang.String nsURI, java.lang.String localName)
setAttributeNS()
, attributeNodeNS()
, setAttributeNodeNS()
, and attribute()
.
public final java.lang.String attributeNS(java.lang.String nsURI, java.lang.String localName, java.lang.String defValue)
setAttributeNS()
, attributeNodeNS()
, setAttributeNodeNS()
, and attribute()
.
public final QDomAttr attributeNode(java.lang.String name)
QDomAttr
object that corresponds to the attribute called name. If no such attribute exists a null attribute
is returned. setAttributeNode()
, attribute()
, setAttribute()
, and attributeNodeNS()
.
public final QDomAttr attributeNodeNS(java.lang.String nsURI, java.lang.String localName)
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. setAttributeNodeNS()
, setAttributeNode()
, attribute()
, and setAttribute()
.
public final QDomNamedNodeMap attributes()
QDomNamedNodeMap
containing all this element's attributes. attribute()
, setAttribute()
, attributeNode()
, and setAttributeNode()
.
public final QDomNodeList elementsByTagName(java.lang.String tagname)
QDomNodeList
containing all descendants of this element named tagname 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. elementsByTagNameNS()
, and QDomDocument::elementsByTagName()
.
public final QDomNodeList elementsByTagNameNS(java.lang.String nsURI, java.lang.String localName)
QDomNodeList
containing all descendants of this element with local name localName and namespace URI nsURI 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. elementsByTagName()
, and QDomDocument::elementsByTagNameNS()
.
public final boolean hasAttribute(java.lang.String name)
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.
public final boolean hasAttributeNS(java.lang.String nsURI, java.lang.String localName)
public final void removeAttribute(java.lang.String name)
setAttribute()
, attribute()
, and removeAttributeNS()
.
public final void removeAttributeNS(java.lang.String nsURI, java.lang.String localName)
setAttributeNS()
, attributeNS()
, and removeAttribute()
.
public final QDomAttr removeAttributeNode(QDomAttr oldAttr)
attributeNode()
, and setAttributeNode()
.
public final void setAttribute(java.lang.String name, java.lang.String value)
attribute()
, setAttributeNode()
, and setAttributeNS()
.
public final void setAttribute(java.lang.String name, double value)
public final void setAttribute(java.lang.String name, float value)
public final void setAttribute(java.lang.String name, int value)
public final void setAttribute(java.lang.String name, long value)
public final void setAttributeNS(java.lang.String nsURI, java.lang.String qName, java.lang.String value)
Although qName is the qualified name, the local name is used to decide if an existing attribute's value should be replaced.
attributeNS()
, setAttributeNodeNS()
, and setAttribute()
.
public final void setAttributeNS(java.lang.String nsURI, java.lang.String qName, double value)
public final void setAttributeNS(java.lang.String nsURI, java.lang.String qName, int value)
public final void setAttributeNS(java.lang.String nsURI, java.lang.String qName, long value)
public final QDomAttr setAttributeNode(QDomAttr newAttr)
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
.
attributeNode()
, setAttribute()
, and setAttributeNodeNS()
.
public final QDomAttr setAttributeNodeNS(QDomAttr newAttr)
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
.
attributeNodeNS()
, setAttributeNS()
, and setAttributeNode()
.
public final void setTagName(java.lang.String name)
tagName()
.
public final java.lang.String tagName()
<img src="myimg.png">the tagname would return "img".
setTagName()
.
public final java.lang.String text()
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 <xml is cool>Comments are ignored by this function. It only evaluates
QDomText
and QDomCDATASection
objects.
public static QDomElement fromNativePointer(QNativePointer nativePointer)
public static QNativePointer nativePointerArray(QDomElement[] array)
public QDomElement clone()
clone
in class QDomNode
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |