← Back to team overview

ubuntu-phone team mailing list archive

Re: Multiple nested levels in a QML XmlListModel

 

I have seen a similar article at
http://stackoverflow.com/questions/19281773/reading-multiple-xml-attributes-with-qml

However, it is still tricky to form the tree architecture that xml has in
the ListModel in QML. I also has a problem in interpreting my xml data. For
example:

<result>
<status>OK</status>
<total_count>40</total_count>
<count>20</count>
<businesses>
<business>
<business_id>7288959</business_id>
<name>
<![CDATA[ 将太无二(这是一条测试商户数据,仅用于测试开发,开发完成后请申请正式数据...) ]]>
</name>
<branch_name>
<![CDATA[ 五彩城店 ]]>
</branch_name>
<address>
<![CDATA[ 海淀区清河中街68号华润五彩城二期六层 ]]>
</address>
<telephone>010-82156252</telephone>
<city>北京</city>
<regions>
<string>海淀区</string>
<string>清河</string>
</regions>
<categories>
<string>日本料理</string>
</categories>
<latitude>40.030502</latitude>
<longitude>116.33278</longitude>
<avg_rating>0.0</avg_rating>
<rating_img_url>http://i2.dpfile.com/s/i/app/api/32_0star.png
</rating_img_url>
<rating_s_img_url>http://i2.dpfile.com/s/i/app/api/16_0star.png
</rating_s_img_url>
<product_grade>0</product_grade>
<decoration_grade>0</decoration_grade>
<service_grade>0</service_grade>
<product_score>0.0</product_score>
<decoration_score>0.0</decoration_score>
<service_score>0.0</service_score>
<avg_price>0</avg_price>
<review_count>0</review_count>
<review_list_url>
http://m.dianping.com/shop/7288959/review_all?utm_source=open
</review_list_url>
<distance>44721660</distance>
<business_url>http://lite.m.dianping.com/nqTvReEdpH</business_url>
<photo_url>
http://i2.dpfile.com/pc/5d6b5924049fc6c0d722f84434da8ce1(700x700)/thumb.jpg
</photo_url>
<s_photo_url>
http://i1.dpfile.com/pc/5d6b5924049fc6c0d722f84434da8ce1(278x200)/thumb.jpg
</s_photo_url>
<photo_count>1570</photo_count>
<photo_list_url>
http://m.dianping.com/shop/7288959/photos?utm_source=open
</photo_list_url>
<has_coupon>0</has_coupon>
<coupon_id>0</coupon_id>
<coupon_description>
<![CDATA[ ]]>
</coupon_description>
<coupon_url/>
<has_deal>1</has_deal>
<deal_count>2</deal_count>
<deals>
<deal>
<id>2-6264628</id>
<description>
<![CDATA[ 将太无二!仅售86元,价值100元代金券,全场通用,可叠加,包厢可用!周末及法定节假日可用! ]]>
</description>
<url>http://lite.m.dianping.com/M3zmmbGQZn</url>
</deal>
<deal>
<id>2-8132265</id>
<description>
<![CDATA[
将太无二!仅售498元,价值600元储值卡,全场通用,可叠加,不限时段通用,包厢可用!将太无二会员卡首度开团,惊喜不容错过!
]]>
</description>
<url>http://lite.m.dianping.com/KsDrsYXO0Z</url>
</deal>
</deals>
<has_online_reservation>0</has_online_reservation>
<online_reservation_url/>
</business>
<business>

I want to have the “name/photo_url" and also the details of the "'deals"
(in which "deal" varies depending on the business). How can we combine them
together into a single ListModel element? This is a a little bit tricky for
me.

Thanks & best regards,
XiaoGuo


On Thu, Apr 16, 2015 at 11:01 PM, Niklas Wenzel <nikwen.developer@xxxxxxxxx>
wrote:

> Hi Simon,
>
> Check out the "xml" property of the XmlListModel. [1]
>
> Try something like the following:
>
> XmlListModel {
>     id: modelOne
>     ...
> }
>
> XmlListModel {
>     id: modelTwo
>     xml: modelOne.xml
> }
>
> That will make the second model use the content the first model
> downloaded. ;)
>
> Cheers,
> Niklas
>
> [1]
> http://doc.qt.io/qt-5/qml-qtquick-xmllistmodel-xmllistmodel.html#xml-prop
>
>
> Am Mi, 15. Apr, 2015 um 9:06 schrieb Simon <hamfilter@xxxxxxxxx>:
>
> Hi everyone, I am learning QML and have a question but ask.ubuntu.com and
> stackoverflow are not as responsive to QML questions as I hoped, is this
> the right place to ask for help? I am wondering how to query a second level
> in an XML file. Currently using an XmlModelList with a ListView but it
> **downloads the same file multiple times** which is clearly not the best
> solution on a phone with a spotty connection.
> https://stackoverflow.com/questions/29189248/multiple-nested-levels-in-a-qml-xmllistmodel
> Thank you! -- Simon
> --
> Mailing list: https://launchpad.net/~ubuntu-phone Post to :
> ubuntu-phone@xxxxxxxxxxxxxxxxxxx Unsubscribe :
> https://launchpad.net/~ubuntu-phone More help :
> https://help.launchpad.net/ListHelp
>
>
> --
> Mailing list: https://launchpad.net/~ubuntu-phone
> Post to     : ubuntu-phone@xxxxxxxxxxxxxxxxxxx
> Unsubscribe : https://launchpad.net/~ubuntu-phone
> More help   : https://help.launchpad.net/ListHelp
>
>


-- 
XiaoGuo, Liu (刘晓国)
Mobile: +86-13911181302

References