473,394 Members | 1,645 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Extracting values from XmlNode/XmlAttribute

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
May 30 '07 #1
5 4719
MaxMax wrote:
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.
Use
<http://msdn2.microsoft.com/en-us/library/system.xml.xmlconvert.toboolean.aspx>
--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
May 30 '07 #2
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.

May 31 '07 #3
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.
Jun 5 '07 #4
On Jun 5, 7:26 am, stch...@online.microsoft.com (Steven Cheng[MSFT])
wrote:
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.

Jun 5 '07 #5
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
Jun 5 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Anita C | last post by:
I have the foll. code to update the value of an attribute: xmlDocument.Load("abc.xml"); XmlAttribute xmlAttrib = xmlDocument.SelectSingleNode(root/web/theme/@desc); xmlAttrib.Value =...
2
by: David Elliott | last post by:
I am creating a configuration class to read / write a standard configuration file. <?xml version="1.0" encoding="utf-8"?> <configuration> <appSettings> <add key="ConnectionString"...
3
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
3
by: Mike | last post by:
I want to be able access an xml file using an XPath? query to go to a specific node. Once I have that node I want to be able to retrieve the value of an attribute. Can't seem to get this working...
5
by: Paul | last post by:
Here I have the definition of an XmlNode which is a property (PayPreference) on my Customer class containing an enum describing how the customer will pay. <PayPerference...
5
by: Mahesh Devjibhai Dhola | last post by:
Hi All, I want to make a custom class in c#, which extends System.Xml.XmlNode class of BCL. Now in custom class, I have implement abstract methods of XmlNode class also. Now when I am trying to...
2
by: Paul | last post by:
Is there a way to test if an XmlNode represents an enum?
3
by: Andy | last post by:
Hello Guys: What am I doing wrong with this code? I can't seem to get it to simply add an attribute to my node. The node already exists. I am simply opening the XMLDocument and creating one...
4
by: CSharper | last post by:
I am reading an XmlFile using XmlDocument and traverse through the XmlNode, as I read I need to append an attribute to the XmlNode on some conditions. I tried xmlNode.Attributes.Append() It...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.