PDA

View Full Version : QDomElement text



emrares
21st December 2010, 07:46
How can i get the text of a single DomElement?

In the documentation it says " the text() function operates recursively to find the text (since not all elements contain text)."

So if i have something like this

<faktoren>
<faktor resolution="1680x1050" fullscreen="5">6</faktor>
<faktor resolution="1280x1024" fullscreen="5">8</faktor>
</faktoren>

and i call the text function on the faktoren tag i get "68" and i should get an empty string.

So my question is how can i get the text value of a single element, and ignore it's child tags?

Lykurg
21st December 2010, 08:12
No you get "68" since it works recursive... If you want get "8" call text() on the tag faktor. Or look if a tag has QTextNode as a child.

emrares
21st December 2010, 08:44
Problem solved. Thanks Lykurg for your advice.


QDomNodeList nodeList = elem.childNodes();


for ( int i = 0; i < nodeList.size(); i++ )
{
QDomElement nodeElement = nodeList.item(i).toElement();
QDomText txtNode = nodeList.item(i).toText();
QString str = txtNode.data();
}