我有這樣的查詢:的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