Early Preview

This is currently very much a preview. Please feel free to try things out, but don't be upset if anything is not yet working. Feedback is welcome over on our GitHub Dicussions page.

class System.​Xml.​XmlConvert

Assembly: System.Xml.ReaderWriter

Inheritance: object → XmlConvert

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

Methods

public static string
DecodeName​(string name)
Decodes a name. This method does the reverse of the <see cref="M:System.Xml.XmlConvert.EncodeName(System.String)" /> and <see cref="M:System.Xml.XmlConvert.EncodeLocalName(System.String)" /> methods.
Returns The decoded name.
name The name to be transformed.
public static string
EncodeLocalName​(string name)
Converts the name to a valid XML local name.
Returns The encoded name.
name The name to be encoded.
public static string
EncodeName​(string name)
Converts the name to a valid XML name.
Returns The name with any invalid characters replaced by an escape string.
name A name to be translated.
public static string
EncodeNmToken​(string name)
Verifies the name is valid according to the XML specification.
Returns The encoded name.
name The name to be encoded.
public static bool
IsNCNameChar​(char ch)
Checks whether the passed-in character is a valid non-colon character type.
Returns <see langword="true" /> if the character is a valid non-colon character type; otherwise, <see langword="false" /> .
ch The character to verify as a non-colon character.
public static bool
IsPublicIdChar​(char ch)
Returns the passed-in character instance if the character in the argument is a valid public id character, otherwise <see langword="null" /> .
Returns The passed-in character if the character is a valid public id character, otherwise <see langword="null" /> .
ch <see cref="T:System.Char" /> object to validate.
public static bool
IsStartNCNameChar​(char ch)
Checks if the passed-in character is a valid Start Name Character type.
Returns <see langword="true" /> if the character is a valid Start Name Character type; otherwise, <see langword="false" /> .
ch The character to validate.
public static bool
IsWhitespaceChar​(char ch)
Checks if the passed-in character is a valid XML whitespace character.
Returns <see langword="true" /> if the passed in character is a valid XML whitespace character; otherwise, <see langword="false" /> .
ch The character to validate.
public static bool
IsXmlChar​(char ch)
Checks if the passed-in character is a valid XML character.
Returns <see langword="true" /> if the passed in character is a valid XML character; otherwise, <see langword="false" /> .
ch The character to validate.
public static bool
IsXmlSurrogatePair​(char lowChar, char highChar)
Checks if the passed-in surrogate pair of characters is a valid XML character.
Returns <see langword="true" /> if the passed in surrogate pair of characters is a valid XML character; otherwise, <see langword="false" /> .
lowChar The surrogate character to validate.
highChar The surrogate character to validate.
public static bool
ToBoolean​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Boolean" /> equivalent.
Returns A <see langword="Boolean" /> value, that is, <see langword="true" /> or <see langword="false" /> .
s The string to convert.
public static byte
ToByte​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Byte" /> equivalent.
Returns A <see langword="Byte" /> equivalent of the string.
s The string to convert.
public static char
ToChar​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Char" /> equivalent.
Returns A <see langword="Char" /> representing the single character.
s The string containing a single character to convert.
public static DateTime
ToDateTime​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.DateTime" /> equivalent.
Returns A <see langword="DateTime" /> equivalent of the string.
s The string to convert.
public static DateTime
ToDateTime​(string s, string format)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.DateTime" /> equivalent.
Returns A <see langword="DateTime" /> equivalent of the string.
s The string to convert.
format The format structure to apply to the converted <see langword="DateTime" /> . Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets. The string is validated against this format.
public static DateTime
ToDateTime​(string s, string[] formats)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.DateTime" /> equivalent.
Returns A <see langword="DateTime" /> equivalent of the string.
s The string to convert.
formats An array containing the format structures to apply to the converted <see langword="DateTime" /> . Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
public static DateTime
ToDateTime​(string s, XmlDateTimeSerializationMode dateTimeOption)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.DateTime" /> using the <see cref="T:System.Xml.XmlDateTimeSerializationMode" /> specified.
Returns A <see cref="T:System.DateTime" /> equivalent of the <see cref="T:System.String" /> .
s The <see cref="T:System.String" /> value to convert.
dateTimeOption One of the enumeration values that specify whether the date should be converted to local time or preserved as Coordinated Universal Time (UTC), if it is a UTC date.
public static DateTimeOffset
ToDateTimeOffset​(string s)
Converts the supplied <see cref="T:System.String" /> to a <see cref="T:System.DateTimeOffset" /> equivalent.
Returns The <see cref="T:System.DateTimeOffset" /> equivalent of the supplied string.
s The string to convert. The string must conform to a subset of the W3C Recommendation for the XML dateTime type. For more information, see the dateTime section of the XML Schema specification.
public static DateTimeOffset
ToDateTimeOffset​(string s, string format)
Converts the supplied <see cref="T:System.String" /> to a <see cref="T:System.DateTimeOffset" /> equivalent.
Returns The <see cref="T:System.DateTimeOffset" /> equivalent of the supplied string.
s The string to convert.
format The format from which <paramref name="s" /> is converted. The format parameter can be any subset of the W3C Recommendation for the XML dateTime type. (For more information, see the dateTime section of the XML Schema specification..) The string <paramref name="s" /> is validated against this format.
public static DateTimeOffset
ToDateTimeOffset​(string s, string[] formats)
Converts the supplied <see cref="T:System.String" /> to a <see cref="T:System.DateTimeOffset" /> equivalent.
Returns The <see cref="T:System.DateTimeOffset" /> equivalent of the supplied string.
s The string to convert.
formats An array of formats from which <paramref name="s" /> can be converted. Each format in <paramref name="formats" /> can be any subset of the W3C Recommendation for the XML dateTime type. (For more information, see the dateTime section of the XML Schema specification..) The string <paramref name="s" /> is validated against one of these formats.
public static decimal
ToDecimal​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Decimal" /> equivalent.
Returns A <see langword="Decimal" /> equivalent of the string.
s The string to convert.
public static double
ToDouble​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Double" /> equivalent.
Returns A <see cref="T:System.Double" /> equivalent of the string.
s The string to convert.
public static Guid
ToGuid​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Guid" /> equivalent.
Returns A <see langword="Guid" /> equivalent of the string.
s The string to convert.
public static short
ToInt16​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Int16" /> equivalent.
Returns An <see cref="T:System.Int16" /> equivalent of the string.
s The string to convert.
public static int
ToInt32​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Int32" /> equivalent.
Returns An <see cref="T:System.Int32" /> equivalent of the string.
s The string to convert.
public static long
ToInt64​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Int64" /> equivalent.
Returns An <see cref="T:System.Int64" /> equivalent of the string.
s The string to convert.
public static sbyte
ToSByte​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.SByte" /> equivalent.
Returns An <see langword="SByte" /> equivalent of the string.
s The string to convert.
public static Single
ToSingle​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.Single" /> equivalent.
Returns A <see cref="T:System.Single" /> equivalent of the string.
s The string to convert.
public static string
ToString​(bool value)
Converts the <see cref="T:System.Boolean" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="Boolean" /> , that is, "true" or "false".
value The value to convert.
public static string
ToString​(byte value)
Converts the <see cref="T:System.Byte" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="Byte" /> .
value The value to convert.
public static string
ToString​(char value)
Converts the <see cref="T:System.Char" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="Char" /> .
value The value to convert.
public static string
ToString​(DateTime value)
Converts the <see cref="T:System.DateTime" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="DateTime" /> in the format yyyy-MM-ddTHH:mm:ss where 'T' is a constant literal.
value The value to convert.
public static string
ToString​(DateTime value, string format)
Converts the <see cref="T:System.DateTime" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="DateTime" /> in the specified format.
value The value to convert.
format The format structure that defines how to display the converted string. Valid formats include "yyyy-MM-ddTHH:mm:sszzzzzz" and its subsets.
public static string
ToString​(DateTime value, XmlDateTimeSerializationMode dateTimeOption)
Converts the <see cref="T:System.DateTime" /> to a <see cref="T:System.String" /> using the <see cref="T:System.Xml.XmlDateTimeSerializationMode" /> specified.
Returns A <see cref="T:System.String" /> equivalent of the <see cref="T:System.DateTime" /> .
value The <see cref="T:System.DateTime" /> value to convert.
dateTimeOption One of the <see cref="T:System.Xml.XmlDateTimeSerializationMode" /> values that specify how to treat the <see cref="T:System.DateTime" /> value.
public static string
ToString​(DateTimeOffset value)
Converts the supplied <see cref="T:System.DateTimeOffset" /> to a <see cref="T:System.String" /> .
Returns A <see cref="T:System.String" /> representation of the supplied <see cref="T:System.DateTimeOffset" /> .
value The <see cref="T:System.DateTimeOffset" /> to be converted.
public static string
ToString​(DateTimeOffset value, string format)
Converts the supplied <see cref="T:System.DateTimeOffset" /> to a <see cref="T:System.String" /> in the specified format.
Returns A <see cref="T:System.String" /> representation in the specified format of the supplied <see cref="T:System.DateTimeOffset" /> .
value The <see cref="T:System.DateTimeOffset" /> to be converted.
format The format to which <paramref name="value" /> is converted. The format parameter can be any subset of the W3C Recommendation for the XML dateTime type. (For more information, see the dateTime section of the XML Schema specification..)
public static string
ToString​(decimal value)
Converts the <see cref="T:System.Decimal" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="Decimal" /> .
value The value to convert.
public static string
ToString​(double value)
Converts the <see cref="T:System.Double" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.Double" /> .
value The value to convert.
public static string
ToString​(Guid value)
Converts the <see cref="T:System.Guid" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="Guid" /> .
value The value to convert.
public static string
ToString​(short value)
Converts the <see cref="T:System.Int16" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.Int16" /> .
value The value to convert.
public static string
ToString​(int value)
Converts the <see cref="T:System.Int32" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.Int32" /> .
value The value to convert.
public static string
ToString​(long value)
Converts the <see cref="T:System.Int64" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.Int64" /> .
value The value to convert.
public static string
ToString​(sbyte value)
Converts the <see cref="T:System.SByte" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="SByte" /> .
value The value to convert.
public static string
ToString​(Single value)
Converts the <see cref="T:System.Single" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.Single" /> .
value The value to convert.
public static string
ToString​(TimeSpan value)
Converts the <see cref="T:System.TimeSpan" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see langword="TimeSpan" /> .
value The value to convert.
public static string
ToString​(ushort value)
Converts the <see cref="T:System.UInt16" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.UInt16" /> .
value The value to convert.
public static string
ToString​(uint value)
Converts the <see cref="T:System.UInt32" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.UInt32" /> .
value The value to convert.
public static string
ToString​(ulong value)
Converts the <see cref="T:System.UInt64" /> to a <see cref="T:System.String" /> .
Returns A string representation of the <see cref="T:System.UInt64" /> .
value The value to convert.
public static TimeSpan
ToTimeSpan​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.TimeSpan" /> equivalent.
Returns A <see langword="TimeSpan" /> equivalent of the string.
s The string to convert. The string format must conform to the W3C XML Schema Part 2: Datatypes recommendation for duration.
public static ushort
ToUInt16​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.UInt16" /> equivalent.
Returns A <see cref="T:System.UInt16" /> equivalent of the string.
s The string to convert.
public static uint
ToUInt32​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.UInt32" /> equivalent.
Returns A <see cref="T:System.UInt32" /> equivalent of the string.
s The string to convert.
public static ulong
ToUInt64​(string s)
Converts the <see cref="T:System.String" /> to a <see cref="T:System.UInt64" /> equivalent.
Returns A <see cref="T:System.UInt64" /> equivalent of the string.
s The string to convert.
public static string
VerifyName​(string name)
Verifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
Returns The name, if it is a valid XML name.
name The name to verify.
public static string
VerifyNCName​(string name)
Verifies that the name is a valid <see langword="NCName" /> according to the W3C Extended Markup Language recommendation. An <see langword="NCName" /> is a name that cannot contain a colon.
Returns The name, if it is a valid NCName.
name The name to verify.
public static string
VerifyNMTOKEN​(string name)
Verifies that the string is a valid NMTOKEN according to the W3C XML Schema Part2: Datatypes recommendation.
Returns The name token, if it is a valid NMTOKEN.
name The string you wish to verify.
public static string
VerifyPublicId​(string publicId)
Returns the passed in string instance if all the characters in the string argument are valid public id characters.
Returns The passed-in string if all the characters in the argument are valid public id characters.
publicId <see cref="T:System.String" /> that contains the id to validate.
public static string
VerifyTOKEN​(string token)
Verifies that the string is a valid token according to the W3C XML Schema Part2: Datatypes recommendation.
Returns The token, if it is a valid token.
token The string value you wish to verify.
public static string
VerifyWhitespace​(string content)
Returns the passed-in string instance if all the characters in the string argument are valid whitespace characters.
Returns The passed-in string instance if all the characters in the string argument are valid whitespace characters, otherwise <see langword="null" /> .
content <see cref="T:System.String" /> to verify.
public static string
VerifyXmlChars​(string content)
Returns the passed-in string if all the characters and surrogate pair characters in the string argument are valid XML characters, otherwise an <see langword="XmlException" /> is thrown with information on the first invalid character encountered.
Returns The passed-in string if all the characters and surrogate-pair characters in the string argument are valid XML characters, otherwise an <see langword="XmlException" /> is thrown with information on the first invalid character encountered.
content <see cref="T:System.String" /> that contains characters to verify.
public bool
Equals​(object obj)
Inherited from object
protected void
Finalize​()
Inherited from object
public int
GetHashCode​()
Inherited from object
public Type
GetType​()
Inherited from object
protected object
MemberwiseClone​()
Inherited from object
public string
ToString​()
Inherited from object