JovianGhost
1st September 2010, 00:58
I'm having a really annoying time with this.
I figured I'd use XML queries rather than manually traversing with XML DOM, because it would make my life easier. Well, so far that's not the case.
I have a sample XML file, as follows:
<root>
<mynode id="1">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
<mynode id="2">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
<mynode id="3">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
<mynode id="4">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
</root>
I want to find all nodes called "mynode".
At first I looked into evaluateTo(QXmlResultItems * result) but this doesn't let me access any properties of the nodes themselves, because QXmlItemis a very simplistic class.
Next I looked at evaluateTo(QStringList * target) but this returns the text of all descendants of "mynode" nodes as well, so I get all the "this is foo" and "this is bar". I don't want this.
What I want is the ability to match a bunch of nodes, and then access/manipulate each one individually. Is this possible?
[edit]
I found this example here: http://stackoverflow.com/questions/1286842/how-do-i-run-xpath-queries-in-qt
But when I run it, elementsByTagName only returns a single mynode, the first one. I don't understand what I'm doing wrong, since "res" contains the whole tree.
I figured I'd use XML queries rather than manually traversing with XML DOM, because it would make my life easier. Well, so far that's not the case.
I have a sample XML file, as follows:
<root>
<mynode id="1">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
<mynode id="2">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
<mynode id="3">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
<mynode id="4">
<foo>this is foo.</foo>
<bar>this is bar.</bar>
</mynode>
</root>
I want to find all nodes called "mynode".
At first I looked into evaluateTo(QXmlResultItems * result) but this doesn't let me access any properties of the nodes themselves, because QXmlItemis a very simplistic class.
Next I looked at evaluateTo(QStringList * target) but this returns the text of all descendants of "mynode" nodes as well, so I get all the "this is foo" and "this is bar". I don't want this.
What I want is the ability to match a bunch of nodes, and then access/manipulate each one individually. Is this possible?
[edit]
I found this example here: http://stackoverflow.com/questions/1286842/how-do-i-run-xpath-queries-in-qt
But when I run it, elementsByTagName only returns a single mynode, the first one. I don't understand what I'm doing wrong, since "res" contains the whole tree.