Accessing data from .XML file with Matlab

2019-06-26 05:02发布

问题:

I've got a .XML file that looks like this:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Comments</key>
<string></string>
<key>DataSummary</key>
<dict>
    <key>AreaCM2</key>
    <real>2.77</real>
    <key>Dev</key>
    <real>9.48</real>
</dict>
<key>DataValues</key>
<array>
    <real>81</real>
    <real>85</real>
</array>
<key>ROIPoints</key>
<array>
    <string>{65.7414, 58.2929}</string>
    <string>{65.7388, 58.4421}</string>
</array>
</dict>
</plist>

I'd like to access DataValues and ROIPoints using MATLAB.

I found quite a far fetched way of extracting ROIPoints which works like this:

DOMnode = xmlread(pathofxmlfile);
i       = DOMnode.getDocumentElement;
f       = char(i.getTextContent);

f is a string containing all the "text" contents:

f = CommentsDataSummaryAreaCM22.77Dev9.48DataValues8185ROIPoints**{65.7414, 58.2929}{65.7388, 58.4421}

Since ROIPoints are enclosed in curly brackets, I can manipulate the string in order to extract them.

Unfortunately, DataValues get horizontally concatenated (8185) and I cant extract them individually.

Any tips?

回答1:

Please check out xml_read on matlab central. It will read your xml and output it as a struct (following your xml tree). It might be slow for larger XML's though.