我有这样的查询:的XPath - 选择节点基于以下同级
/plist/dict[1]/dict/dict/dict/key/following-sibling::dict/string[string()='Algier']
我真正想选择的是“关键”节点一个(只以下同胞::字典之前)。
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();
}
}
}
}
好像嵌套以下同胞不工作。 例如像:
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是越野车和不符合... –
难怪诺基亚现在是它的地方。 :( – zakishaheen
我看了这个,我同意,如果QML在给定的XPath表达式上抛出上面的错误,QML有一个错误。当没有'('?)时,为什么在这个世界中会期待''''?你能提交一个错误报告吗? – LarsH