[Qt-interest] How to access QDomNode's value?

Oliver.Knoll at comit.ch Oliver.Knoll at comit.ch
Thu Jul 22 15:39:27 CEST 2010


Kai Koehne wrote on Thursday, July 22, 2010 9:37 AM:

> On 7/21/2010 5:50 PM, ext Eeli Reilin wrote:
>> Hi,
>> 
>> I'm trying to get the QDomNode's value(the string between the tags),
>> and only getting an empty string.
>> ...
>>    <root>
>>    	<foo>bar</foo>
>>    </root>
> ...
> Try something like
> 
> QDomElement fooElement =
> doc.documentElement().firstChildElement("foo"); // ..
> QString fooValue = fooElement.text();

That's correct :) To understand a bit more the background /why/ we have to query the value of the (first) *child* of <foo> (instead of the <foo> node directly): the XML text "bar" is /also/ considered to be a QDomNode, specifically a http://doc.trolltech.com/4.6/qdomtext.html, whereas the parent node - <foo> - would be a http://doc.trolltech.com/4.6/qdomelement.html (I guess, not sure anymore). So yes, <foo> is the parent of text node "bar".

Cheers, Oliver
-- 
Oliver Knoll
Dipl. Informatik-Ing. ETH
COMIT AG - ++41 79 520 95 22



More information about the Qt-interest-old mailing list