QML处理xml使用的是XmlListModel + XmlRole,基本的操作可以参考官方文档,说的很清楚。
使用query查询目标节点时,如果包含 namespace,如“a:book”,则会查询到null。
如果声明的是默认命名空间,如
<xml_api_reply xmlns="http://duino.com/" version="1">
需要如下处理:
<RSSxmlns:yweather="http://xml.weather.yahoo.com/ns/RSS/1.0"version="2.0">
......
<yweather:forecastday="Tue"date="24 Feb 2015"low="11"high="17"text="Partly Cloudy"code="30"/>
......
需要如下处理:
query才可以查询到相应的数据。
- <span style="white-space:pre"> </span>XmlListModel {
- <span style="white-space:pre"> </span>id: weatherModelForecast
- source: "http://weather.yahooapis.com/forecastRSS?w=2133704&u=c"
- query: "/RSS/channel/item/yweather:forecast"
- <strong><span style="color:#ff0000;">namespaceDeclarations: "declare namespace yweather='http://xml.weather.yahoo.com/ns/RSS/1.0';"</span></strong>
- XmlRole { name: "day"; query: "@day/string()" }
- XmlRole { name: "date"; query: "@date/string()" }
- XmlRole { name: "low"; query: "@low/string()" }
- XmlRole { name: "high"; query: "@high/string()" }
- XmlRole { name: "text"; query: "@text/string()" }
- }
参考文档:https://msdn.microsoft.com/zh-cn/library/ms190945(v=sql.105).aspx