help using Xpath and XML reading
Mostrar comentarios más antiguos
Dear all,
I'm recently new to using Matlab to navigate through an XML file, and have a feeling theres a simple answer to my query starting me in the face. I have an XML file which contains coordinates of 3 objects that come from a different program. I'm trying to import the coordinates of these objects and associated image number (identified by integer) into Matlab. I'm able to find the coordinates of each object individually, but would anyone know of a loop I could use as other XML files are a few hundred entries long
Heres my Matlab code so far:
import javax.xml.xpath.*
factory = XPathFactory.newInstance;
xpath = factory.newXPath;
expression = xpath.compile('plist/dict/array/dict/array');
coordinate_node = expression.evaluate(docNode, XPathConstants.STRING)
I tried the following, which does find 3 instances of "<array>" but simply outputs the same set of coordinates 3 times.
expression = xpath.compile('plist/dict/array/dict/array');
nodeList = expression.evaluate(docNode, XPathConstants.NODESET)
for i = 1:nodeList.getLength
node = nodeList.item(i-1);
coordinate_node{i} = expression.evaluate(docNode, XPathConstants.STRING)
end
And below is the XML file:
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<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>
</array>
<key>Slice</key>
<integer>58</integer>
<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>
<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>
</array>
</dict>
</plist>
Any help greatly appreciated!
Jim
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Structured Data and XML Documents en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!