public class XmlConvert
Object
XmlConvert
System.Xml
XML
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.
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 type CLI data type hexBinary A Byte array base64Binary A Byte array Boolean Boolean Byte SByte normalizedString String Date DateTime duration TimeSpan dateTime DateTime decimal Decimal Double Double ENTITIES A String array ENTITY String Float Single gMonthDay DateTime gDay DateTime gYear DateTime gYearMonth DateTime ID String IDREF String IDREFS A String array int Int32 integer Decimal language String long Int64 month DateTime Name String NCName String negativeInteger Decimal NMTOKEN String NMTOKENS A String array nonNegativeInteger Decimal nonPositiveInteger Decimal NOTATION String positiveInteger Decimal short Int16 string String time DateTime timePeriod DateTime token String unsignedByte Byte unsignedInt UInt32 unsignedLong UInt64 unsignedShort UInt16 anyURI Uri
System.Xml Namespace
XmlConvert Constructors
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
public XmlConvert();
Constructs a new instance of the XmlConvert class.
System.Xml.XmlConvert Class, System.Xml Namespace
public static string DecodeName(string name);
Decodes a name.
- name
- A String specifying the name to be decoded.
A String containing the decoded name.
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.
- Names are decoded from left to right.
- Any sequence
_xHHHH_
(whereHHHH
stands for a valid, four digit hexadecimal UCS-2 code) that has not been previously decoded is transformed into the corresponding Unicode 2.1 (Unicode 3.0 if supported by the application) character.- No short forms are recognized. They are passed on without translation. For example, "_x70_" or "__" are not decoded.
]
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 isOrder #1i : Order #1x0069_ : Order #1_x69_
System.Xml.XmlConvert Class, System.Xml Namespace
public static string EncodeLocalName(string name);
Converts a name to a valid XML local name.
- name
- A String specifying the name to be encoded.
A String containing the XML local name. If name isnull
or System.String.Empty, name is returned.
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.
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 isLocalName _x0037__x003A__x002B_
Name _x0037_:_x002B_
NmToken 7:_x002B_
System.Xml.XmlConvert Class, System.Xml Namespace
public static string EncodeName(string name);
Converts a name to a valid XML name.
- name
- A String specifying the name to be encoded.
A String containing the XML name. If name isnull
or System.String.Empty, name is returned.
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_
. TheHHHH
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.
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.
System.Xml.XmlConvert Class, System.Xml Namespace
public static string EncodeNmToken(string name);
Converts a name to a valid XML name token.
- name
- A String specifying the name to be encoded.
A String containing the XML name token. If name isnull
or System.String.Empty, name is returned.
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.
System.Xml.XmlConvert Class, System.Xml Namespace
public static bool ToBoolean(string s);
Converts a String to a Boolean equivalent.
- s
- The String to convert.
The Boolean equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s does not represent a Boolean value.
This method removes leading and trailing white space. After this trimming, valid strings are "1" and "true", which returntrue
, and "0" and "false", which returnfalse
.
System.Xml.XmlConvert Class, System.Xml Namespace
public static byte ToByte(string s);
Converts a String to a Byte equivalent.
- s
- The String to convert.
The Byte equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Byte.MinValue or greater than System.Byte.MaxValue.
This method calls System.Byte.Parse(System.String)(s, System.Globalization.NumberStyles.AllowLeadingWhite|System.Globalization.NumberStyles.AllowTrailingWhite, System.Globalization.NumberFormatInfo.InvariantInfo).
System.Xml.XmlConvert Class, System.Xml Namespace
public static char ToChar(string s);
Converts a String to a Char equivalent.
- s
- The string containing a single character to convert.
The Char equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s contains more than one character.
This method calls System.Char.Parse(System.String)(s).
System.Xml.XmlConvert Class, System.Xml Namespace
public static DateTime ToDateTime(string s, string[] formats);
Converts a String to a DateTime equivalent.
- s
- The String to convert.
- formats
- A String array specifying formats used to validate s.
The DateTime equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s 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.
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.
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 is9/18/1966 8:45:11 PM
System.Xml.XmlConvert Class, System.Xml Namespace
public static DateTime ToDateTime(string s, string format);
Converts a String to a DateTime equivalent.
- s
- The String to convert.
- format
- A String specifying the format used to validate s.
The DateTime equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s or format is System.String.Empty . -or-
s does not contain a date and time that corresponds to format.
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.
System.Xml.XmlConvert Class, System.Xml Namespace
public static DateTime ToDateTime(string s);
Converts a String to a DateTime equivalent.
- s
- The String to convert.
The DateTime equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is System.String.Empty or is not in the correct format.
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"
System.Xml.XmlConvert Class, System.Xml Namespace
public static decimal ToDecimal(string s);
Converts a String to a Decimal equivalent.
- s
- The String to convert.
The Decimal equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Decimal.MinValue or greater than System.Decimal.MaxValue.
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).
ExtendedNumerics
System.Xml.XmlConvert Class, System.Xml Namespace
public static double ToDouble(string s);
Converts a String to a Double equivalent.
- s
- The String to convert.
The Double equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Double.MinValue or greater than System.Double.MaxValue.
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).
ExtendedNumerics
System.Xml.XmlConvert Class, System.Xml Namespace
public static short ToInt16(string s);
Converts a String to a Int16 equivalent.
- s
- The String to convert.
The Int16 equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Int16.MinValue or greater than System.Int16.MaxValue.
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).
System.Xml.XmlConvert Class, System.Xml Namespace
public static int ToInt32(string s);
Converts a String to a Int32 equivalent.
- s
- The String to convert.
The Int32 equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Int32.MinValue or greater than System.Int32.MaxValue.
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).
System.Xml.XmlConvert Class, System.Xml Namespace
public static long ToInt64(string s);
Converts a String to a Int64 equivalent.
- s
- The String to convert.
The Int64 equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Int64.MinValue or greater than System.Int64.MaxValue.
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).
System.Xml.XmlConvert Class, System.Xml Namespace
public static sbyte ToSByte(string s);
Converts a String to a SByte equivalent.
- s
- The String to convert.
The SByte equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.SByte.MinValue or greater than System.SByte.MaxValue.
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).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static float ToSingle(string s);
Converts a String to a Single equivalent.
- s
- The String to convert.
The Single equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.Single.MinValue or greater than System.Single.MaxValue.
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).
ExtendedNumerics
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(long value);
Converts a Int64 to a String .
- value
- The Int64 to convert.
The String representation of value.
This method calls value.ToString(null
, System.Globalization.NumberFormatInfo.InvariantInfo).
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(int value);
Converts a Int32 to a String .
- value
- The Int32 to convert.
The String representation of value.
This method calls value.ToString(null
, System.Globalization.NumberFormatInfo.InvariantInfo ).
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(short value);
Converts a Int16 to a String.
- value
- The Int16 to convert.
The String representation of value.
This method calls value.ToString(null
, System.Globalization.NumberFormatInfo.InvariantInfo ).
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(byte value);
Converts a Byte to a String .
- value
- The Byte to convert.
The String representation of value.
This method calls value.ToString(null
, System.Globalization.NumberFormatInfo.InvariantInfo ).
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(ushort value);
Converts a UInt16 to a String .
- value
- The UInt16 to convert.
The String representation of value.
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 ).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(uint value);
Converts a UInt32 to a String .
- value
- The UInt32 to convert.
The String representation of value.
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 ).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(ulong value);
Converts a UInt64 to a String .
- value
- The UInt64 to convert.
The String representation of value.
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).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(float value);
Converts a Single to a String .
- value
- The Single to convert.
The String representation of value.
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).
ExtendedNumerics
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(double value);
Converts a Char to a String .
- value
- The Char to convert.
The String representation of value.
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).
ExtendedNumerics
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(TimeSpan value);
Converts a TimeSpan to a String.
- value
- The TimeSpan to convert.
The String representation of value.
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 isP3DT11H59M6.128S
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(DateTime value);
Converts a DateTime to a String .
- value
- The DateTime to convert.
The String representation of value.
This method calls System.Xml.XmlConvert.ToString(System.Boolean)(value, "yyyy-MM-ddTHH:mm:ss.fffffffzzzzzz").
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(DateTime value, string format);
Converts a DateTime to a String .
- 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.
The String representation of value in the specified format..
This method calls value.ToString(format, System.Globalization.DateTimeFormatInfo.InvariantInfo).
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(sbyte value);
Converts a SByte to a String .
- value
- The SByte to convert.
The String representation of value.
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 ).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(decimal value);
Converts a Decimal to a String .
- value
- The Decimal to convert.
The String representation of value.
This method calls value.ToString(null
, System.Globalization.NumberFormatInfo.InvariantInfo ).
ExtendedNumerics
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(char value);
Converts a Char to a String.
- value
- The Char to convert.
The String representation of value.
This method calls value.ToString(null
).
System.Xml.XmlConvert Class, System.Xml Namespace
public static string ToString(bool value);
Converts a Boolean to a String.
- value
- The Boolean to convert.
The String "true" or the String "false".
System.Xml.XmlConvert Class, System.Xml Namespace
public static TimeSpan ToTimeSpan(string s);
Converts a String to a TimeSpan equivalent.
- s
- The String to convert.
The TimeSpan equivalent of s.
Exception Type Condition FormatException s is not in the correct format to represent a TimeSpan value.
System.Xml.XmlConvert Class, System.Xml Namespace
public static ushort ToUInt16(string s);
Converts a String to a UInt16 equivalent.
- s
- The String to convert.
The UInt16 equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.UInt16.MinValue or greater than System.UInt16.MaxValue.
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).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static uint ToUInt32(string s);
Converts a String to a UInt32 equivalent.
- s
- The String to convert.
The UInt32 equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.UInt32.MinValue or greater than System.UInt32.MaxValue.
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).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static ulong ToUInt64(string s);
Converts a String to a UInt64 equivalent.
- s
- The String to convert.
The UInt64 equivalent of s.
Exception Type Condition ArgumentNullException s is a null reference. FormatException s is not in the correct format. OverflowException s represents a number less than System.UInt64.MinValue or greater than System.UInt64.MaxValue.
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).
CLSCompliantAttribute(false)
System.Xml.XmlConvert Class, System.Xml Namespace
public static string VerifyNCName(string name);
Verifies that the name is a valid qualified name as defined in the W3C Extended Markup Language recommendation (REC-xml-names-19990114).
- name
- A String specifying the name to verify.
The Stringname, if it is a valid XML qualified name.
Exception Type Condition ArgumentNullException name is null
or System.String.Empty.XmlException name is not a valid XML qualified name.
If name contains a colon, XmlException is thrown.
System.Xml.XmlConvert Class, System.Xml Namespace
public static string VerifyName(string name);
Verifies that the name is a valid name as defined in the W3C Extended Markup Language recommendation (REC-xml-names-19990114).
- name
- A String specifying the name to verify.
The Stringname, if it is a valid XML name.
Exception Type Condition ArgumentNullException name is null
or System.String.Empty.XmlException name is not a valid XML name.
System.Xml.XmlConvert Class, System.Xml Namespace