如何在 qml/qt 的 xpath 查询中获取当前项目的父项?fn:parent()
未实现,../
是的,但对我不起作用。
好像是 focus
问题。
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()" }
}
最佳答案
告诉模型从哪里进行查询的源标签在哪里?
您需要声明来源,您的 ID 属性在节点之外。并且必须声明使用的命名空间(例如 http://www.w3.org/2005/Atom )。所以我认为你的代码必须是这样的:
XmlListModel {
query: "/groups/group/"
namespaceDeclarations: "declare namespace group=\"http://www.w3.org/2005/Atom/\";"
source: "url of your xml file"
XmlRole { name: "group_id"; query: "../@id/string()" }
}
关于xml - qml/qt 中带有 xpath 的父项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7498718/