tags:

views:

85

answers:

1

Hello everyone.

I'm parsing a fairly complicated XML file of the following structure:

<root>
...
...
<item>
<subitem id="1"/>
<text>
text1
</text>
</item>
<item>
<subitem id="2"/>
<text>
text2
</text>
</item>
...
<item>
...
</item>
...
</root>

It's pretty crude but you get my drift I hope. I'm primarily interested in "item" nodes. So I wrote the following code (directly out of the Qt's online manual):

QXmlQuery query;
query.setQuery("//item/");

QXmlResultItems result;
query.evaluateTo(&result);

QXmlItem item(result.next());
while (!item.isNull()) 
{
  if (item.isNode())
  {
      // WHAT DO I DO NOW?
  }
  item = result.next();
}

Now, QXmlItem appears to represent two concepts, a literal value (like a string) or a Node, (which is what item.isNode() is doing). Unfortunately, I can't grasp how to convert the QXmlItem to something that will query-able again. In particular from the example above I'd like to grab the "id" attribute, and the text element. Can I do this using the XQuery approach, or am I way off base here?

Any advice?

Thanks!

A: 

QXmlQuery is one crummy piece of Qt documentation, but i would say that you write your query to return the items that you actually want i.e. (this is an uneducated guess)

query.setQuery("//item/subitem | //item/text");

W3Schools has a Tutorial on XPath that might help

Harald Scheirich
Worth a try, I'll give it a go.
EightyEight