Getting field name from XML-File
-
I am a QT beginner. And I want to get the value of the tag where Filed name = "aaa". I tired using
@XmlRole { name: "aaa"; query: "aaa/string()"@But it did not work.
Its a great help if anyone can help me.
@
<?xml version="1.0" ?>
<program><meta>
<field name="aaa" >something</field>
<field name="bbb" >ccccce</field>
<description>descriptiontext</description>
<date></date>
</meta><parameters>
<parameter id = "z">
<description>some useful parameter</description>
<type id="integer">
<default>5</default>
<min>0</min>
<max>10</max>
</type>
</parameter>
@Edit: XML is sort-of code too - Welcome at DevNet!; Andre
-
Hello,
I don't know why you're posting in the way that helping you is almost impossible, however I'll try!
How are you using this XmlRole? It does not work "itself". How you checked the "XmlRole":http://doc.qt.nokia.com/4.7-snapshot/qml-xmlrole.html documentation? There is nice example with it, and you can use it in pretty straightforward way.
-
If you have a xml file like that, then here is one example of how you can do what you want:
@
XmlListModel {
...
query: "/program"XmlRole { name: "aaa"; query: "meta/field[@name='aaa']/string()" } ...
}
@That XmlRole returns string value of the element field having an attribute name with value of aaa
Note that because name is an attribute then in XmlRole's query you need to use @name instead of nameI recommend that you read eg. W3C School's XPath tutorial:
http://www.w3schools.com/xpath/There is also other XPath tutorials in internet.
-
Thank you Mika. I tried and it works fine. I read the article of Xpath.