Parsing an XML file

2 views (last 30 days)
Jason
Jason on 7 Dec 2015
Answered: Adam on 7 Dec 2015
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=redNumberOfImages=4Read=First/>
<Exposure Name=greenNumberOfImages=4Read=First/>
<Exposure Name=redNumberOfImages=5Read=First/>
<Exposure Name=greenNumberOfImages=4Read=First/>
..
<Exposure Name=redNumberOfImages=6Read=Second/>
<Exposure Name=greenNumberOfImages=7Read=Second/>
<Exposure Name=redNumberOfImages=8Read=Second/>
<Exposure Name=greenNumberOfImages=9Read=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

Answers (1)

Adam
Adam on 7 Dec 2015
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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!