[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 -
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 -
"Query" uses the Xpath syntax. You can find some info here:
http://www.w3schools.com/xpath/xpath_syntax.asp