Extracting values from XmlNode/XmlAttribute

M

MaxMax

If I have an XmlNode/XmlAttribute and I want to convert its value to a
"native" c# type (for example boolean), how should I do? I can't (for
example) simply use Boolean.TryParse, because Xml Boolean considers 0 and 1
to be "good" values for a boolean type.

--- bye
 
S

Steven Cheng[MSFT]

Hi Max,

As Martin has suggested, you can use the XmlConvert class to convert the
string value(you pick from XmlNode or XmlAttribute ) to the target
type(boolean, integer .....). It is just like the System.Convert class, the
only difference is that XmlConvert class is specific to XML standard awared
convertion.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
S

Steven Cheng[MSFT]

Hi Max,

Have you got any further progress or does the suggestion in previous reply
helps you some? If there is still anything we can help, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead


This posting is provided "AS IS" with no warranties, and confers no rights.
 
A

Aneesh Pulukkul

Hi Max,

Have you got any further progress or does the suggestion in previous reply
helps you some? If there is still anything we can help, please feel free to
post here.

Sincerely,

Steven Cheng

Microsoft MSDN Online Support Lead

This posting is provided "AS IS" with no warranties, and confers no rights.

I think XMLConvert should work for you. Else we can think of using
reflection.
 
M

MaxMax

Have you got any further progress or does the suggestion in previous reply
helps you some? If there is still anything we can help, please feel free
to
post here.
Yes yes... Simply I wasn't able to find it in the MSDN the first time....
There are so many classes :)

--- bye
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top