qml/qt 中带有 xpath 的父项
如何在 qml/qt 的 xpath 查询中获取当前项目的父项? fn:parent()
未实现, ../
是的,但对我不起作用。 看起来像是一个焦点
问题。
xml 示例:
<groups>
<group id="A">
<item>bla</item>
<item>blah</item>
</group>
<group id="B">
<item>bla</item>
<item>blah</item>
</group>
<group id="C">
<item>bla</item>
<item>blah</item>
</group>
</groups>
以下 XmlRole 返回空字符串:
XmlListModel {
query: "/groups/group/item"
XmlRole { name: "group_id"; query: "../@id/string()" }
}
How do I get the parent for the current item in an xpath query in qml/qt ?fn:parent()
isn't implemented, ../
yes but doesn't work for me.
Seems like a focus
problem.
xml example:
<groups>
<group id="A">
<item>bla</item>
<item>blah</item>
</group>
<group id="B">
<item>bla</item>
<item>blah</item>
</group>
<group id="C">
<item>bla</item>
<item>blah</item>
</group>
</groups>
The following XmlRole returns an empty string:
XmlListModel {
query: "/groups/group/item"
XmlRole { name: "group_id"; query: "../@id/string()" }
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
告诉模型从哪里进行查询的源标签在哪里?
您需要声明来源,您的 ID 属性位于节点之外。并且必须声明使用的命名空间(例如 http://www.w3.org/2005/Atom)。所以我认为你的代码必须是这样的:
Where is the source tag that tell the model from where take the query?
You need to declare the source, your ID property is outside of node. And have to declare the namespace used(for example http://www.w3.org/2005/Atom). So i think that your code have to be like:
试试这个 XPath:
参考:http://www.w3.org/TR/xpath/#section -字符串函数
Try this XPath:
Reference: http://www.w3.org/TR/xpath/#section-String-Functions
这在 XPath 1.0 中是无效语法。
您确定使用的是 XPath 2.0 引擎吗?
在 XPath 1.0 中使用:
string(../@id
)或者,如果需要选择节点集的表达式,则只需使用:
This is invalid syntax in XPath 1.0.
Are you sure you are using an XPath 2.0 engine?
In XPath 1.0 use:
string(../@id
)Or, if an expression that selects a node-set is required, then simply use:
看来您缺少源标签....xml 文件的位置。
尽管有关查询语法的其他讨论仍然相关。
It does appear that you are missing the source tag.... the location of the xml file.
Although the other discussion regarding the query syntax is still relevant.