I have an xml like:
<a>
<b>1</b>
<c>2</c>
<d>3</d>
</a>
and a recursive function that parses QDomDocument
that wraps it. The function iterates QDomNode
s, converting them into QDomElement
s and calls text()
method to get data.
Unfortunately QDomElement::text()
works at <a>
level too and returns: 123
. So it gathers the texts of all nested elements.
I would like it to return an empty string bcs, I would rather not checking tagName()
value as there are may be plenty of them. So I would rather chek node tag by haveng/not having text inside than vice versa. Is this doable? Is there a method that will return empty string for <a>
and text values for <b>, <c>, <d>
levels?
P.S. QDomNode::nodeValue()
returns an empty text for all elements.
It seems I was wrong bcs I was not iterating
QDomNode
s that can't be converted toQDomElement
s. And according to this answer:I have no markup inside
<b>
-like elements. So at<b>
element's level I'm havingel.childNodes().size() == 1
,el.firstChild().isElement() == false
andel.firstChild().nodeValue()
returns a non-empty value!