PDA

View Full Version : How to get Text value of a QDomElement ? (noob question)



BillGates
30th August 2010, 11:17
Hi,
say I have QDomElement containing :



<text:p>
etc etc etc etc,
<text:s/>
blablabla bla bla bla bla bla
</text:p>


How do i get the string "etc etc etc etc, <text:s/> blablabla bla bla bla bla bla" ?
I tried .totext().data() but it doesnt appear to work.

What is the proper course of action ?

BillGates
30th August 2010, 13:59
Well, so i made a function to parse element, wish there was an more handy way, but such is life. :)

aamer4yu
30th August 2010, 14:22
The above code is not valid.
You cannot have <> as text. You will need to use CDATA..

_Stefan
30th August 2010, 15:11
If you browse through a QDomElement, you can use ::tagName() to get the name between < and >.
If you need the value of the tag, so the text between <tag> your text here </tag>, you can just use the ::text() method of QDomElement.

As easy as that ;)

wysota
30th August 2010, 23:14
Iterate over all child nodes, use QDomNode::save() to save each of them to a string. Then concatenate all strings you received and you're done. Or don't use DOM but rather some smarter approach :)

BillGates
31st August 2010, 12:38
Thanks all for replying,

Wysota, i am curious as to what you mean by smarter approach :D. And thanks for suggesting ::save(), i wasnt aware of it, this is primarily why i asked here on the forum, in hope of someone suggesting some functions i wasnt aware of. Qt is big! But it doesnt feel bloated at all (to me).

have a nice day

wysota
31st August 2010, 15:01
Wysota, i am curious as to what you mean by smarter approach :D
QXmlStreamReader