PDA

View Full Version : Work with QXmlResultItems



icwiener
1st July 2013, 16:59
Hi,

is it possible to select an element from an XML file with XPath, check its contents for certain criteria and then select one of its siblings?



<List>
<Item>
<Data>
<Hierarchy>Item</Hierarchy>
<ShortName>MyItem</ShortName>
<Name>ReallyMyItem</Name>
</Data>
</Item>
<Item>
<Data>
<Hierarchy>SubItem</Hierarchy>
<ShortName>MySubItem</ShortName>
<Name>ReallyMySubItem</Name>
</Data>
</Item>
</List>

So I want to get the name of every item that is an "Item", but not of "SubItem"s.

I tried to fetch the whole "Data" and try to get out the info but failed to get the query for the sub part valid, so I abandoned that idea.
Now I am fetching the "Hierarchy" into a QXmlResultItems element. Then I run over it in a loop and find all "Item"s. But what then? Can I access its siblings from the resulting QXmlItem by any chance?

Or is my attempt wrong in the first place? All this XML stuff is kind of hard to grasp for me. :(

Regards

icwiener
2nd July 2013, 09:13
Hi,

now I solved it in a for me unexpectedly easy way. XPath can do what I want and I solved it like this now.


/List/Item/Data[Hierarchy="Item"]/Name

This way, I get all names from only those data items matching "Item".

Regards