Parsing an XML file
显示 更早的评论
Hi.
I have an xml file that I need to scroll down to find information under the heading Exposure. the general format is as below.
I need to pull out the "number of Images" number in a list for all the red and all the green exposures and count them.
<Exposure>
<Exposure Name=“red” NumberOfImages=“4” Read=“First”/>
<Exposure Name=“green” NumberOfImages=“4” Read=“First”/>
<Exposure Name=“red” NumberOfImages=“5” Read=“First”/>
<Exposure Name=“green” NumberOfImages=“4” Read=“First”/>
…..
<Exposure Name=“red” NumberOfImages=“6” Read=“Second”/>
<Exposure Name=“green” NumberOfImages=“7” Read=“Second”/>
<Exposure Name=“red” NumberOfImages=“8” Read=“Second”/>
<Exposure Name=“green” NumberOfImages=“9” Read=“Second”/>
so in the above, I need an two arrays, one for green and one for red such as (for red)
1 Red 4 First
1 Red 5 First
..
1 Red 6 Second
1 Red 8 Second
Im not to sure how to continue with my attempt:
fid=fopen(fileR);
while ~feof(fid)
l=fgetl(fid);
if strfind(l,'Exposures')
%Found begining of expsoures, continue
l2=fgetl(fid);
if strfind(l2,'Exposure Name="red')
....now what??
end
end
回答(1 个)
Adam
2015-12-7
doc xmlread
would probably be better. It is not intuitive code and objects to work with, but once you get used to it it works well to extract exactly what you are looking for.
类别
在 帮助中心 和 File Exchange 中查找有关 Structured Data and XML Documents 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!