加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

QML处理xml---查询含命名空间的节点

发布时间:2020-12-16 06:27:26 所属栏目:百科 来源:网络整理
导读:QML处理xml使用的是XmlListModel + XmlRole,基本的操作可以参考官方文档,说的很清楚。 使用query查询目标节点时,如果包含 namespace,如“a:book”,则会查询到null。 如果声明的是默认命名空间,如 xml_api_reply xmlns="http://duino.com/" version="1"

QML处理xml使用的是XmlListModel + XmlRole,基本的操作可以参考官方文档,说的很清楚。

使用query查询目标节点时,如果包含 namespace,如“a:book”,则会查询到null。

如果声明的是默认命名空间,如

<xml_api_reply xmlns="http://duino.com/" version="1">

需要如下处理:

XmlListModel {
    source: "http://mysite.com/feed.xml"
    query: "/feed/entry"
    <strong><span style="color:#ff0000;">namespaceDeclarations: "declare default element namespace 'http://duino.com/';"</span></strong>

    XmlRole { name: "title"; query: "title/string()" }
}


如果是

<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"/>

......

需要如下处理:

<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()" }
	}
query才可以查询到相应的数据。


参考文档:https://msdn.microsoft.com/zh-cn/library/ms190945(v=sql.105).aspx

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读