How to unify the code for reading XML file with varied field length?

1 view (last 30 days)
To read the attribute value in an xml file like below with single field (length=1)
<A Xvalue="3">
</A>
I use AXvalue = A.Attributes.Xvalue to the value 3.
To read multiple attribute values in an xml file like below with two same fields with different attribute values:
<A Xvalue="3">
</A>
<A Xvalue="4">
</A>
I need to first get the length of the fields (how many fields) using ALth = Length(A) and then use following code
for iA=1:ALth
AXvalue = A{1,iA}.Attributes.Xvalue
end
Above case would not work for the case with ALth=1. So it would not work for the first case.
I am looking for a way to unify the code to get the attributes of above two different cases, no matter the value of ALth > or = 1. Is there any way to do that?
Thanks...
  1 Comment
Jarrod Rivituso
Jarrod Rivituso on 31 Oct 2012
Hi Bruce,
Are you using a file exchange tool, such as xml2struct? Forgive my ignorance, but how do you convert your XML data to the format where you can enter
A{1,iA}.Attributes.Xvalue
-Jarrod

Sign in to comment.

Answers (0)

Tags

Community Treasure Hunt

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

Start Hunting!