[Qt-interest] How to access QDomNode's value?
Kai Koehne
kai.koehne at nokia.com
Thu Jul 22 09:37:23 CEST 2010
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.
>
> Let's say that I have an XML data like this:
>
> <root>
> <foo>bar</foo>
> </root>
> I have tried to read the value like this:
>
> QDomDocument doc;
> QDomNode fooNode = doc.documentElement().firstChildElement("foo");
>
> if(fooNode.isNull()) {
> qDebug()<< "Error: could not find Foo!";
> return;
> }
>
> QString fooValue = fooNode.nodeValue();
>
Try something like
QDomElement fooElement = doc.documentElement().firstChildElement("foo");
// ..
QString fooValue = fooElement.text();
See also http://doc.trolltech.com/4.7-snapshot/qdomnode.html and related
help pages.
> I would obviously want fooValue to contain "bar", but all I get is an
> empty string.
>
> I'm totally lost on this, so please help me!
>
>
> Best regards,
> Eeli Reilin
>
>
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
--
Kai Koehne
Software Engineer
Nokia, Qt Development Frameworks
Nokia gate5 GmbH
Firmensitz: Invalidenstr. 117, 10115 Berlin, Germany
Registergericht: Amtsgericht Charlottenburg, Berlin: HRB 106443 B
Umsatzsteueridentifikationsnummer: DE 812 845 193
Geschäftsführer: Dr. Michael Halbherr, Karim Tähtivuori
More information about the Qt-interest-old
mailing list