Export (0) Print
Expand All
This topic has not yet been rated - Rate this topic

Conversion of XML Data Types

The majority of the methods found in an XmlConvert class are used to convert data between strings and strongly-typed formats. Methods are locale independent. This means that they do not take into account any locale settings when doing conversion.

The following sample reads a string and converts it to a DateTime type.

Given the following XML input:

Input

<Element>2001-02-27T11:13:23</Element>

This code converts the string to the DateTime format:

reader.ReadStartElement();
DateTime vDateTime = XmlConvert.ToDateTime(reader.ReadString());
Console.WriteLine(vDateTime);

The following sample reads an Int32 and converts it to a string.

Given the following XML input:

Input

<TestInt32>-2147483648</TestInt32>

This code converts the Int32 into a String:

Int32 vInt32=-2147483648;
writer.WriteElementString("TestInt32",XmlConvert.ToString(vInt32));
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft. All rights reserved.