System.Xml.XmlConvert Class

public class XmlConvert

Base Types

Object
  XmlConvert

Assembly

System.Xml

Library

XML

Summary

Encodes and decodes XML names and provides methods for converting between common language infrastructure (CLI) types and XML Schema Definition language (XSD) types. When converting data types, the values returned are locale independent.

Description

Element and attribute names or ID values are limited to a range of XML characters according to the Extensible Markup Language (XML) 1.0 (Second Edition) recommendation, located at www.w3.org/TR/2000/REC-xml-20001006.html. When names contain invalid characters, they need to be translated into valid XML names.

Many languages and applications allow Unicode characters in their names, which are not valid in XML names. For example, if 'Order Detail' were a column heading in a database, the database allows the space between the words Order and Detail. However, in XML, the space between Order and Detail is considered an invalid XML character. Thus, the space, the invalid character, needs to be converted into an escaped hexadecimal encoding and can be decoded later.

The System.Xml.XmlConvert.EncodeName(System.String) and System.Xml.XmlConvert.DecodeName(System.String) methods are used to translate invalid XML names into valid XML names and vice versa.

XmlConvert provides methods that enable the conversion of a String to a CLI data type and vice-versa. Locale settings are not taken into account during data conversion.

XmlConvert also provides methods that convert between XML Schema Definition (XSD) data types (see http://www.w3.org/TR/xmlschema-2/#built-in-datatypes) and their corresponding common language infrastructure (CLI) data types. The following table shows the XSD data types and their corresponding CLI data types.

XSD data typeCLI data type
hexBinaryA Byte array
base64BinaryA Byte array
BooleanBoolean
ByteSByte
normalizedStringString
DateDateTime
durationTimeSpan
dateTimeDateTime
decimalDecimal
DoubleDouble
ENTITIESA String array
ENTITYString
FloatSingle
gMonthDayDateTime
gDayDateTime
gYearDateTime
gYearMonthDateTime
IDString
IDREFString
IDREFSA String array
intInt32
integerDecimal
languageString
longInt64
monthDateTime
NameString
NCNameString
negativeIntegerDecimal
NMTOKENString
NMTOKENSA String array
nonNegativeIntegerDecimal
nonPositiveIntegerDecimal
NOTATIONString
positiveIntegerDecimal
shortInt16
stringString
timeDateTime
timePeriodDateTime
tokenString
unsignedByteByte
unsignedIntUInt32
unsignedLongUInt64
unsignedShortUInt16
anyURIUri

See Also

System.Xml Namespace

Members

XmlConvert Constructors

XmlConvert Constructor

XmlConvert Methods

XmlConvert.DecodeName Method
XmlConvert.EncodeLocalName Method
XmlConvert.EncodeName Method
XmlConvert.EncodeNmToken Method
XmlConvert.ToBoolean Method
XmlConvert.ToByte Method
XmlConvert.ToChar Method
XmlConvert.ToDateTime(System.String, System.String[]) Method
XmlConvert.ToDateTime(System.String, System.String) Method
XmlConvert.ToDateTime(System.String) Method
XmlConvert.ToDecimal Method
XmlConvert.ToDouble Method
XmlConvert.ToInt16 Method
XmlConvert.ToInt32 Method
XmlConvert.ToInt64 Method
XmlConvert.ToSByte Method
XmlConvert.ToSingle Method
XmlConvert.ToString(long) Method
XmlConvert.ToString(int) Method
XmlConvert.ToString(short) Method
XmlConvert.ToString(byte) Method
XmlConvert.ToString(ushort) Method
XmlConvert.ToString(uint) Method
XmlConvert.ToString(ulong) Method
XmlConvert.ToString(float) Method
XmlConvert.ToString(double) Method
XmlConvert.ToString(System.TimeSpan) Method
XmlConvert.ToString(System.DateTime) Method
XmlConvert.ToString(System.DateTime, System.String) Method
XmlConvert.ToString(sbyte) Method
XmlConvert.ToString(System.Decimal) Method
XmlConvert.ToString(char) Method
XmlConvert.ToString(bool) Method
XmlConvert.ToTimeSpan Method
XmlConvert.ToUInt16 Method
XmlConvert.ToUInt32 Method
XmlConvert.ToUInt64 Method
XmlConvert.VerifyNCName Method
XmlConvert.VerifyName Method


XmlConvert Constructor

public XmlConvert();

Summary

Constructs a new instance of the XmlConvert class.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.DecodeName Method

public static string DecodeName(string name);

Summary

Decodes a name.

Parameters

name
A String specifying the name to be decoded.

Return Value

A String containing the decoded name.

Description

Names are decoded using the following rules:

[Note: This method does the reverse of the System.Xml.XmlConvert.EncodeName(System.String), System.Xml.XmlConvert.EncodeLocalName(System.String), and System.Xml.XmlConvert.EncodeNmToken(System.String) methods.

]

Example

The following example demonstrates the valid and invalid character formats for decoding.

using System;
using System.Xml;

public class App {

  public static void Main() {

    Console.WriteLine( "{0} : {1} : {2}",
      // _x0069_ decodes to i
      XmlConvert.DecodeName("Order #1_x0069_"),

      // missing beginning _
      XmlConvert.DecodeName("Order #1x0069_"),

      // short form
      XmlConvert.DecodeName("Order #1_x69_") ); 
  }
}
   
The output is

Order #1i : Order #1x0069_ : Order #1_x69_

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.EncodeLocalName Method

public static string EncodeLocalName(string name);

Summary

Converts a name to a valid XML local name.

Parameters

name
A String specifying the name to be encoded.

Return Value

A String containing the XML local name. If name is null or System.String.Empty, name is returned.

Description

This method is similar to the System.Xml.XmlConvert.EncodeName(System.String) method except that it encodes the colon (:) character, which guarantees that the name can be used as the local name part of a namespace qualified name.

Example

The following example compares the System.Xml.XmlConvert.EncodeLocalName(System.String), System.Xml.XmlConvert.EncodeName(System.String), and System.Xml.XmlConvert.EncodeNmToken(System.String) methods when the name to be encoded is "7:+".

using System;
using System.Xml;

public class App {

  public static void Main() {

    Console.WriteLine( "LocalName  {0}",
      XmlConvert.EncodeLocalName("7:+") ); 
    Console.WriteLine( "Name  {0}",
      XmlConvert.EncodeName("7:+") );
    Console.WriteLine( "NmToken  {0}",
      XmlConvert.EncodeNmToken("7:+") );
  }
}
The output is

LocalName _x0037__x003A__x002B_

Name _x0037_:_x002B_

NmToken 7:_x002B_

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.EncodeName Method

public static string EncodeName(string name);

Summary

Converts a name to a valid XML name.

Parameters

name
A String specifying the name to be encoded.

Return Value

A String containing the XML name. If name is null or System.String.Empty, name is returned.

Description

This method translates invalid characters, such as spaces or half-width Katakana, that need to be mapped to XML names without the support or presence of schemas. The invalid characters are translated into escaped numeric entity encodings.

The escape character is '_'. Any XML name character that does not conform to the W3C Extensible Markup Language (XML) 1.0 specification is escaped as _xHHHH_. The HHHH string stands for the four-digit hexadecimal UCS-2 code for the character in most significant bit first order. For example, the name "Order Details" is encoded as "Order_x0020_Details".

The underscore character does not need to be escaped unless it is followed by a character sequence that together with the underscore can be misinterpreted as an escape sequence when decoding the name. No short forms are encoded. For example, the forms "_x20_" and "__" are not encoded.

This method guarantees the name is valid according to the XML specification. It allows colons in any position, which means the name might still be invalid according to the W3C Namespace Specification (www.w3.org/TR/REC-xml-names). To guarantee it is a valid namespace qualified name use the System.Xml.XmlConvert.EncodeLocalName(System.String) method for the prefix and local name parts and join the result with a colon.

Example

See the System.Xml.XmlConvert.EncodeLocalName(System.String) method for an example comparing the System.Xml.XmlConvert.EncodeLocalName(System.String), System.Xml.XmlConvert.EncodeName(System.String), and System.Xml.XmlConvert.EncodeNmToken(System.String) methods.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.EncodeNmToken Method

public static string EncodeNmToken(string name);

Summary

Converts a name to a valid XML name token.

Parameters

name
A String specifying the name to be encoded.

Return Value

A String containing the XML name token. If name is null or System.String.Empty, name is returned.

Example

See the System.Xml.XmlConvert.EncodeLocalName(System.String) method for an example comparing the System.Xml.XmlConvert.EncodeLocalName(System.String), System.Xml.XmlConvert.EncodeName(System.String), and System.Xml.XmlConvert.EncodeNmToken(System.String) methods.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToBoolean Method

public static bool ToBoolean(string s);

Summary

Converts a String to a Boolean equivalent.

Parameters

s
The String to convert.

Return Value

The Boolean equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions does not represent a Boolean value.

Description

This method removes leading and trailing white space. After this trimming, valid strings are "1" and "true", which return true , and "0" and "false", which return false .

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToByte Method

public static byte ToByte(string s);

Summary

Converts a String to a Byte equivalent.

Parameters

s
The String to convert.

Return Value

The Byte equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Byte.MinValue or greater than System.Byte.MaxValue.

Description

This method calls System.Byte.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToChar Method

public static char ToChar(string s);

Summary

Converts a String to a Char equivalent.

Parameters

s
The string containing a single character to convert.

Return Value

The Char equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions contains more than one character.

Description

This method calls System.Char.Parse(System.String)(s).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToDateTime(System.String, System.String[]) Method

public static DateTime ToDateTime(string s, string[] formats);

Summary

Converts a String to a DateTime equivalent.

Parameters

s
The String to convert.
formats
A String array specifying formats used to validate s.

Return Value

The DateTime equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions or an element of formats is System.String.Empty.

-or-

s does not contain a date and time that corresponds to any of the elements of formats.

Description

This method calls System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider)(s, formats, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AllowLeadingWhite|System.Globalization.DateTimeStyles.AllowTrailingWhite).

This method allows s to be validated against multiple formats.

Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.

Example

The following example converts a String to a DateTime and writes the result to the console.

using System;
using System.Xml;

public class App {

  public static void Main() {

    String someDate = "1966-09-19T03:45:11Z";
    String[] datetimeFormats = new String[]
      {"HH:mm:ss", "yyyy-MM-ddTHH:mm:ssZ"};
    DateTime dateTime =
      XmlConvert.ToDateTime(someDate, datetimeFormats);
    Console.WriteLine( "{0}", dateTime.ToString() );
  }
}
The output is

9/18/1966 8:45:11 PM

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToDateTime(System.String, System.String) Method

public static DateTime ToDateTime(string s, string format);

Summary

Converts a String to a DateTime equivalent.

Parameters

s
The String to convert.
format
A String specifying the format used to validate s.

Return Value

The DateTime equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions or format is System.String.Empty .

-or-

s does not contain a date and time that corresponds to format.

Description

This method calls System.DateTime.ParseExact(System.String,System.String,System.IFormatProvider)(s, format, System.Globalization.DateTimeFormatInfo.InvariantInfo, System.Globalization.DateTimeStyles.AllowLeadingWhite|System.Globalization.DateTimeStyles.AllowTrailingWhite).

Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToDateTime(System.String) Method

public static DateTime ToDateTime(string s);

Summary

Converts a String to a DateTime equivalent.

Parameters

s
The String to convert.

Return Value

The DateTime equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is System.String.Empty or is not in the correct format.

Description

s is required to be in one of the following string formats or a FormatException is thrown.

"yyyy-MM-ddTHH:mm:ss"

"yyyy-MM-ddTHH:mm:ss.f"

"yyyy-MM-ddTHH:mm:ss.ff"

"yyyy-MM-ddTHH:mm:ss.fff"

"yyyy-MM-ddTHH:mm:ss.ffff"

"yyyy-MM-ddTHH:mm:ss.fffff"

"yyyy-MM-ddTHH:mm:ss.ffffff"

"yyyy-MM-ddTHH:mm:ss.fffffff"

"yyyy-MM-ddTHH:mm:ssZ"

"yyyy-MM-ddTHH:mm:ss.fZ"

"yyyy-MM-ddTHH:mm:ss.ffZ"

"yyyy-MM-ddTHH:mm:ss.fffZ"

"yyyy-MM-ddTHH:mm:ss.ffffZ"

"yyyy-MM-ddTHH:mm:ss.fffffZ"

"yyyy-MM-ddTHH:mm:ss.ffffffZ"

"yyyy-MM-ddTHH:mm:ss.fffffffZ"

"yyyy-MM-ddTHH:mm:sszzzzzz"

"yyyy-MM-ddTHH:mm:ss.fzzzzzz"

"yyyy-MM-ddTHH:mm:ss.ffzzzzzz"

"yyyy-MM-ddTHH:mm:ss.fffzzzzzz"

"yyyy-MM-ddTHH:mm:ss.ffffzzzzzz"

"yyyy-MM-ddTHH:mm:ss.fffffzzzzzz"

"yyyy-MM-ddTHH:mm:ss.ffffffzzzzzz"

"yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz"

"HH:mm:ss"

"HH:mm:ss.f"

"HH:mm:ss.ff"

"HH:mm:ss.fff"

"HH:mm:ss.ffff"

"HH:mm:ss.fffff"

"HH:mm:ss.ffffff"

"HH:mm:ss.fffffff"

"HH:mm:ssZ"

"HH:mm:ss.fZ"

"HH:mm:ss.ffZ"

"HH:mm:ss.fffZ"

"HH:mm:ss.ffffZ"

"HH:mm:ss.fffffZ"

"HH:mm:ss.ffffffZ"

"HH:mm:ss.fffffffZ"

"HH:mm:sszzzzzz"

"HH:mm:ss.fzzzzzz"

"HH:mm:ss.ffzzzzzz"

"HH:mm:ss.fffzzzzzz"

"HH:mm:ss.ffffzzzzzz"

"HH:mm:ss.fffffzzzzzz"

"HH:mm:ss.ffffffzzzzzz"

"HH:mm:ss.fffffffzzzzzz"

"yyyy-MM-dd"

"yyyy-MM-ddZ"

"yyyy-MM-ddzzzzzz"

"yyyy-MM"

"yyyy-MMZ"

"yyyy-MMzzzzzz"

"yyyy"

"yyyyZ"

"yyyyzzzzzz"

"--MM-dd"

"--MM-ddZ"

"--MM-ddzzzzzz"

"---dd"

"---ddZ"

"---ddzzzzzz"

"--MM--"

"--MM--Z"

"--MM--zzzzzz"

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToDecimal Method

public static decimal ToDecimal(string s);

Summary

Converts a String to a Decimal equivalent.

Parameters

s
The String to convert.

Return Value

The Decimal equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue.

Description

This method calls System.Decimal.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowDecimalPoint|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Library

ExtendedNumerics

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToDouble Method

public static double ToDouble(string s);

Summary

Converts a String to a Double equivalent.

Parameters

s
The String to convert.

Return Value

The Double equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Double.MinValue or greater than System.Double.MaxValue.

Description

If s is "-INF", this method returns System.Double.NegativeInfinity.

If s is "INF", this method returns System.Double.PositiveInfinity.

Otherwise, this method calls System.Double.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowDecimalPoint|System.Globalization.NumberStyles.AllowExponent|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Library

ExtendedNumerics

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToInt16 Method

public static short ToInt16(string s);

Summary

Converts a String to a Int16 equivalent.

Parameters

s
The String to convert.

Return Value

The Int16 equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Int16.MinValue or greater than System.Int16.MaxValue.

Description

This method calls System.Int16.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToInt32 Method

public static int ToInt32(string s);

Summary

Converts a String to a Int32 equivalent.

Parameters

s
The String to convert.

Return Value

The Int32 equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue.

Description

This method calls System.Int32.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToInt64 Method

public static long ToInt64(string s);

Summary

Converts a String to a Int64 equivalent.

Parameters

s
The String to convert.

Return Value

The Int64 equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Int64.MinValue or greater than System.Int64.MaxValue.

Description

This method calls System.Int64.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToSByte Method

public static sbyte ToSByte(string s);

Summary

Converts a String to a SByte equivalent.

Parameters

s
The String to convert.

Return Value

The SByte equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.SByte.MinValue or greater than System.SByte.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToInt16(System.String)(String).

This method calls System.SByte.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToSingle Method

public static float ToSingle(string s);

Summary

Converts a String to a Single equivalent.

Parameters

s
The String to convert.

Return Value

The Single equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.Single.MinValue or greater than System.Single.MaxValue.

Description

If s is "-INF", this method returns System.Single.NegativeInfinity.

If s is "INF", this method returns System.Single.PositiveInfinity.

Otherwise, this method calls System.Single.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowDecimalPoint|System.Globalization.NumberStyles.AllowExponent|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Library

ExtendedNumerics

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(long) Method

public static string ToString(long value);

Summary

Converts a Int64 to a String .

Parameters

value
The Int64 to convert.

Return Value

The String representation of value.

Description

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(int) Method

public static string ToString(int value);

Summary

Converts a Int32 to a String .

Parameters

value
The Int32 to convert.

Return Value

The String representation of value.

Description

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(short) Method

public static string ToString(short value);

Summary

Converts a Int16 to a String.

Parameters

value
The Int16 to convert.

Return Value

The String representation of value.

Description

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(byte) Method

public static string ToString(byte value);

Summary

Converts a Byte to a String .

Parameters

value
The Byte to convert.

Return Value

The String representation of value.

Description

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(ushort) Method

public static string ToString(ushort value);

Summary

Converts a UInt16 to a String .

Parameters

value
The UInt16 to convert.

Return Value

The String representation of value.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToString(System.Boolean)(Int32).

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(uint) Method

public static string ToString(uint value);

Summary

Converts a UInt32 to a String .

Parameters

value
The UInt32 to convert.

Return Value

The String representation of value.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToString(System.Boolean)(Int64).

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(ulong) Method

public static string ToString(ulong value);

Summary

Converts a UInt64 to a String .

Parameters

value
The UInt64 to convert.

Return Value

The String representation of value.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToString(System.Boolean)(Decimal).

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(float) Method

public static string ToString(float value);

Summary

Converts a Single to a String .

Parameters

value
The Single to convert.

Return Value

The String representation of value.

Description

If value is System.Double.NegativeInfinity, this method returns "-INF".

If value is System.Double.PositiveInfinity, this method returns "INF".

Otherwise, this method calls value.ToString("R", System.Globalization.NumberFormatInfo.InvariantInfo).

Library

ExtendedNumerics

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(double) Method

public static string ToString(double value);

Summary

Converts a Char to a String .

Parameters

value
The Char to convert.

Return Value

The String representation of value.

Description

If value is System.Double.NegativeInfinity, this method returns "-INF".

If value is System.Double.PositiveInfinity, this method returns "INF".

Otherwise, this method calls value.ToString("R", System.Globalization.NumberFormatInfo.InvariantInfo).

Library

ExtendedNumerics

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(System.TimeSpan) Method

public static string ToString(TimeSpan value);

Summary

Converts a TimeSpan to a String.

Parameters

value
The TimeSpan to convert.

Return Value

The String representation of value.

Example

The following example converts a TimeSpan to a String and writes the result to the console.

using System;
using System.Xml;

public class App {

  public static void Main() {

    TimeSpan timeSpan = new TimeSpan(3, 11, 59, 6, 128);
    Console.WriteLine( "{0}",
      XmlConvert.ToString(timeSpan) );
  }
}
The output is

P3DT11H59M6.128S

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(System.DateTime) Method

public static string ToString(DateTime value);

Summary

Converts a DateTime to a String .

Parameters

value
The DateTime to convert.

Return Value

The String representation of value.

Description

This method calls System.Xml.XmlConvert.ToString(System.Boolean)(value, "yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz").

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(System.DateTime, System.String) Method

public static string ToString(DateTime value, string format);

Summary

Converts a DateTime to a String .

Parameters

value
The DateTime to convert.
format
A String specifying the format to apply to value. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.

Return Value

The String representation of value in the specified format..

Description

This method calls value.ToString(format, System.Globalization.DateTimeFormatInfo.InvariantInfo).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(sbyte) Method

public static string ToString(sbyte value);

Summary

Converts a SByte to a String .

Parameters

value
The SByte to convert.

Return Value

The String representation of value.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToString(System.Boolean)(Int16).

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(System.Decimal) Method

public static string ToString(decimal value);

Summary

Converts a Decimal to a String .

Parameters

value
The Decimal to convert.

Return Value

The String representation of value.

Description

This method calls value.ToString(null , System.Globalization.NumberFormatInfo.InvariantInfo ).

Library

ExtendedNumerics

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(char) Method

public static string ToString(char value);

Summary

Converts a Char to a String.

Parameters

value
The Char to convert.

Return Value

The String representation of value.

Description

This method calls value.ToString(null ).

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToString(bool) Method

public static string ToString(bool value);

Summary

Converts a Boolean to a String.

Parameters

value
The Boolean to convert.

Return Value

The String "true" or the String "false".

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToTimeSpan Method

public static TimeSpan ToTimeSpan(string s);

Summary

Converts a String to a TimeSpan equivalent.

Parameters

s
The String to convert.

Return Value

The TimeSpan equivalent of s.

Exceptions

Exception TypeCondition
FormatExceptions is not in the correct format to represent a TimeSpan value.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToUInt16 Method

public static ushort ToUInt16(string s);

Summary

Converts a String to a UInt16 equivalent.

Parameters

s
The String to convert.

Return Value

The UInt16 equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.UInt16.MinValue or greater than System.UInt16.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToInt32(System.String)(String).

This method calls System.UInt16.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToUInt32 Method

public static uint ToUInt32(string s);

Summary

Converts a String to a UInt32 equivalent.

Parameters

s
The String to convert.

Return Value

The UInt32 equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.UInt32.MinValue or greater than System.UInt32.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToInt64(System.String)(String).

This method calls System.UInt32.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.ToUInt64 Method

public static ulong ToUInt64(string s);

Summary

Converts a String to a UInt64 equivalent.

Parameters

s
The String to convert.

Return Value

The UInt64 equivalent of s.

Exceptions

Exception TypeCondition
ArgumentNullExceptions is a null reference.
FormatExceptions is not in the correct format.
OverflowExceptions represents a number less than System.UInt64.MinValue or greater than System.UInt64.MaxValue.

Description

This member is not CLS-compliant. For a CLS-compliant alternative, use System.Xml.XmlConvert.ToDecimal(System.String)(String).

This method calls System.UInt64.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingSign|System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).

Attributes

CLSCompliantAttribute(false)

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.VerifyNCName Method

public static string VerifyNCName(string name);

Summary

Verifies that the name is a valid qualified name as defined in the W3C Extended Markup Language recommendation (REC-xml-names-19990114).

Parameters

name
A String specifying the name to verify.

Return Value

The Stringname, if it is a valid XML qualified name.

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null or System.String.Empty.
XmlExceptionname is not a valid XML qualified name.

Description

If name contains a colon, XmlException is thrown.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace

XmlConvert.VerifyName Method

public static string VerifyName(string name);

Summary

Verifies that the name is a valid name as defined in the W3C Extended Markup Language recommendation (REC-xml-names-19990114).

Parameters

name
A String specifying the name to verify.

Return Value

The Stringname, if it is a valid XML name.

Exceptions

Exception TypeCondition
ArgumentNullExceptionname is null or System.String.Empty.
XmlExceptionname is not a valid XML name.

See Also

System.Xml.XmlConvert Class, System.Xml Namespace