【发布时间】:2011-11-24 08:25:36
【问题描述】:
我有一个这样的查询:
/plist/dict[1]/dict/dict/dict/key/following-sibling::dict/string[string()='Algier']
我真正想要选择的是“关键”节点(就在下面的兄弟::dict 之前)之一。
xml是这样的:
<?xml version="1.0" encoding="UTF-8"?>
<plist version="1.0">
<dict>
<key>en_GB</key>
<dict>
<key>Africa</key>
<dict>
<key>Algeria</key>
<dict>
<key>60390</key>
<dict>
<key>NAME</key>
<string>Algier</string>
<key>LATITUDE</key>
<string>36.7500</string>
<key>LONGITUDE</key>
<string>3.0500</string>
</dict>
<key>60391</key>
<dict>
<key>NAME</key>
<string>Some other city</string>
<key>LATITUDE</key>
<string>36.7500</string>
<key>LONGITUDE</key>
<string>3.0500</string>
</dict>
</dict>
</dict>
</dict>
</dict>
</plist>
换句话说,当城市名称为“阿尔及尔”时,我想选择“60390”或(当城市名称为“其他城市”时选择 60391)。
我在 QML XmlListModel 中执行此操作。
更新代码 使用的 QML:
import QtQuick 1.0
Rectangle {
id: container;
width: 360
height: 360
function onLocationModelLoaded(){
console.debug(weLocationModel.count);
}
XmlListModel{
id: weLocationModel;
source: "we_locations.plist";
query: "/*/dict/dict/dict/dict/key[following-sibling::dict[1]/key[.='NAME' and following-sibling::string[1] = 'Algier']]"
XmlRole{
name: "cityId";
query: "name()";
}
onStatusChanged: {
if (status == XmlListModel.Ready){
console.debug("Location Model Ready");
container.onLocationModelLoaded();
}
}
}
}
嵌套的 following-sibling 似乎不起作用。 例如:
query: "/*/dict/dict/dict/dict/key[following-sibling::dict[1]/key[.='NAME']]"
这两个总是返回:
Error XPST0003 in file:///Users/Ali/qtprojects/welocationtest-build-simulator/welocationtest.app/Contents/MacOS/welocationtest, at line 2, column 97: syntax error, unexpected ], expecting )
Error XPST0003 in file:///Users/Ali/qtprojects/welocationtest-build-simulator/welocationtest.app/Contents/MacOS/welocationtest, at line 2, column 91: syntax error, unexpected ], expecting end of file
file:///Users/Ali/qtprojects/welocationtest-build-simulator/welocationtest.app/Contents/Resources/qml/welocationtest/main.qml:17:9: QML XmlRole: invalid query: "name()"
Location Model Ready
0
有没有可能 QML 不遵循 XPath 标准?该解决方案适用于所有其他路径编辑器。
【问题讨论】:
-
似乎 QML 有问题且不合规......
-
难怪诺基亚是现在的位置。 :(
-
我查看了这个,我同意,如果 QML 在给定的 XPath 表达式上抛出上述错误,QML 有一个错误。当没有
(时,为什么它会期待)?你能提交错误报告吗? -
似乎错误是针对:
query: "name()";。您实际上想在此处指定什么?