How to get the numeric value from text after parsing an xml file?

I use xml2struct to read the xml file into a structure. However, the format of all info are text. For example, attributes z='18' was read in as a text with 1 and 8.
How can I get the numeric 18 and use it for calculation?
Thanks...

 Accepted Answer

I've run into this kind of thing. After calling xml2struct, "walk" the structure and use str2num on anything you want as a numeric instead of text.

5 Comments

Ken: thanks for your answer. I tried use str2num, i got error message:
??? Error using ==> str2num at 33
Requires string or character array input.
Error in ==> m_Plot at 33
str2num(xxx)
I checked xxx and it shows as:
xxx =
Text: '149.75'
xxx must be an object or struct, try str2num(xxx.Text)
Thanks for your reply. However, there is still error:
??? Reference to non-existent field 'text'.
Error in ==> m_Plot at 36
str2num(xxx.text)
Do you have any solution?
Basically, what I want to do is to get the data from an xml file c.xml like below
<a a1='2'>
<a3>3</a3>
</a>
I use "xml2struct" in file exchange to parse the above xml file d=xml2struct('c.xml') and then use str2num(d.a.Attributes.a1) to get the attribute a1's value 2. However, I came across the problems I asked here when I use str2num(d.a.a3).
Besides using "xml2struct", is there any other efficient solution to get the values of attributes and others?
Thanks much.
Try upper-case "T" in "Text" -- the first message suggests it is upper case and MATLAB is case sensitive.

Sign in to comment.

More Answers (0)

Tags

Asked:

on 10 Mar 2012

Community Treasure Hunt

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

Start Hunting!