Parsing an XML file

2 次查看(过去 30 天)
Jason
Jason 2015-12-7
回答: Adam 2015-12-7
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

回答(1 个)

Adam
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.

类别

Help CenterFile 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!

Translated by