我使用这个优秀的论坛来教自己一些基本的 xpath 来查询 .XML 文件。我在这里有一个 XML 文件的示例,我正在尝试使用 Matlab 在 XML 文件中导入 3 个对象的 [X,Y] 坐标:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>ROI array</key>
<array>
<dict>
<key>Comments</key>
<string></string>
<key>Name</key>
<string>Unnamed</string>
<key>ROIPoints</key>
<array>
<string>{129.24051549947484, 263.66036033996352}</string>
<string>{114.61421850240453, 278.56760216125258}</string>
<string>{123.11826208150609, 289.73859978088149}</string>
<string>{125.11111111111111, 295.77777777777777}</string>
</array>
<key>Slice</key>
<integer>58</integer>
</dict>
<dict>
<key>Comments</key>
<string></string>
<key>Name</key>
<string>Unnamed</string>
<key>ROIPoints</key>
<array>
<string>{127.09352448499425, 261.31629753478774}</string>
<string>{112.50917389905675, 277.25509453185805}</string>
<string>{126.061969309213, 291.36980247863539}</string>
<string>{141.48499634778722, 292.16234398254164}</string>
<string>{149.71229126966222, 277.81281090148696}</string>
</array>
<key>Slice</key>
<integer>59</integer>
</dict>
<dict>
<key>Comments</key>
<string></string>
<key>Name</key>
<string>Unnamed</string>
<key>ROIPoints</key>
<array>
<string>{134.32833430087788, 258.21743274101027}</string>
<string>{117.0812182120107, 266.44891620048293}</string>
<string>{114.41427180087788, 292.20427203544386}</string>
<string>{128.80573603427632, 299.11905932792433}</string>
<string>{147.92307612216695, 299.11905932792433}</string>
<string>{152.73700281894429, 285.80526996024855}</string>
<string>{154.32626673495992, 268.51202655204543}</string>
</array>
<key>Slice</key>
<integer>60</integer>
</dict>
</array>
</dict>
</plist>
我已经设法使用这个 Matlab 代码导出所有坐标:
expression_2 = xpath.compile('plist/dict/array/dict/array/string');
nodeList_2 = expression_2.evaluate(docNode, XPathConstants.NODESET);
for i = 1:nodeList_2.getLength
node = nodeList_2.item(i-1);
coordinate_node{i} = char(node.getFirstChild.getNodeValue);
end
有谁知道 xpath 查询,我可以计算每个对象中 [X,Y] 坐标的数量?即返回第一个对象的 4 个坐标、第二个对象的 5 个坐标和第三个对象的 7 个坐标的东西?
谢谢,吉姆