[Solved]XmlListModel problem
-
Hi All,
I have a problem when I trying get the data from xml.
My question is how can I get 'Shanghai' and 'Beijing' at the same time,
My code as below: @
import QtQuick 1.0XmlListModel {
id: cityModelsource: "city.xml" query: "/cities/city" // ======> when I try to use '/cities/[A-B]/city' it is doesn't work. XmlRole { name: "name"; query: "name/string()" } XmlRole { name: "id"; query: "id/string()" }
}
city.xml:
<?xml version="1.0" encoding="UTF-8"?>
<cities>
<alphas><alpha>A</alpha></alphas>
<A>
<city><id>2231</id><name>Shanghai</name></city>
</A>
<alphas><alpha>B</alpha></alphas>
<B>
<city><id>3321</id><name>Beijing</name></city>
</B>
</cities>@Edit : please add @ tags,
tags added; Eddy -
It's hard to understand this without formatting. Can you enclose the code in code tags so we can see better?
I'm going to need to see the XML in its correct format.
-
Hi,
You should be able to get all cities using
@query: "/cities//city"@
or
@query: "/cities/*/city"@
If you only wanted e.g. the cities under A and B but not those under C, you could also try something like
@query: "/cities/*[self::A or self::B]/city"@
(in theory I think "/cities/A/city | /cities/B/city" should also work, but XmlListModel doesn't currently support this)
Regards,
Michael -
Hi Michael,
I used "/cities//city", now It works! Thank you very much.
Can you give some information about the answer, If I can't find more information about 'query:' in Qt Assistant where can I find it?
Regards,
Leaf -
"Query" uses the Xpath syntax. You can find some info here:
http://www.w3schools.com/xpath/xpath_syntax.asp