XmlConvert Class

XmlConvert Class

[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]

Encodes and decodes XML names and provides methods for converting between common language runtime types. When converting data types the values returned are locale independent.

System::Object
  System.Xml::XmlConvert

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

No code example is currently available or this language may not be supported.

The XmlConvert type exposes the following members.

  NameDescription
Public methodXmlConvertInitializes a new instance of the XmlConvert class.
Top

  NameDescription
Public methodStatic memberDecodeNameDecodes a name. This method does the reverse of the EncodeName and EncodeLocalName methods.
Public methodStatic memberEncodeLocalNameConverts the name to a valid XML local name.
Public methodStatic memberEncodeNameConverts the name to a valid XML name.
Public methodStatic memberEncodeNmTokenVerifies the name is valid according to the XML specification.
Public methodEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodFinalizeAllows an object to try to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection. (Inherited from Object.)
Public methodGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberIsNCNameCharChecks if the passed-in character is a valid Name Character type.
Public methodStatic memberIsPublicIdCharChecks if the passed in character is a valid PUBLIC ID character.
Public methodStatic memberIsStartNCNameCharChecks if the passed-in character is a valid Start Name Character type.
Public methodStatic memberIsWhitespaceCharChecks if the passed in character is a valid XML whitespace character.
Public methodStatic memberIsXmlCharChecks if the passed in character is a valid XML character.
Public methodStatic memberIsXmlSurrogatePairChecks if the passed in surrogate pair of characters is a valid XML character.
Protected methodMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberToBooleanConverts the String to a Boolean equivalent.
Public methodStatic memberToByteConverts the String to a Byte equivalent.
Public methodStatic memberToCharConverts the String to a Char equivalent.
Public methodStatic memberToDateTime(String, String)Converts the String to a DateTime equivalent.
Public methodStatic memberToDateTime(String, array<String>)Converts the String to a DateTime equivalent.
Public methodStatic memberToDateTime(String, XmlDateTimeSerializationMode)Converts the String to a DateTime using the XmlDateTimeSerializationMode specified
Public methodStatic memberToDateTimeOffset(String)Converts the supplied String to a DateTimeOffset equivalent.
Public methodStatic memberToDateTimeOffset(String, String)Converts the supplied String to a DateTimeOffset equivalent.
Public methodStatic memberToDateTimeOffset(String, array<String>)Converts the supplied String to a DateTimeOffset equivalent.
Public methodStatic memberToDecimalConverts the String to a Decimal equivalent.
Public methodStatic memberToDoubleConverts the String to a Double equivalent.
Public methodStatic memberToGuidConverts the String to a Guid equivalent.
Public methodStatic memberToInt16Converts the String to a Int16 equivalent.
Public methodStatic memberToInt32Converts the String to a Int32 equivalent.
Public methodStatic memberToInt64Converts the String to a Int64 equivalent.
Public methodStatic memberToSByteConverts the String to a SByte equivalent.
Public methodStatic memberToSingleConverts the String to a Single equivalent.
Public methodToString()Returns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberToString(Boolean)Converts the Boolean to a String.
Public methodStatic memberToString(Char)Converts the Char to a String.
Public methodStatic memberToString(DateTimeOffset)Converts the supplied DateTimeOffset to a String.
Public methodStatic memberToString(Decimal)Converts the Decimal to a String.
Public methodStatic memberToString(Double)Converts the Double to a String.
Public methodStatic memberToString(Guid)Converts the Guid to a String.
Public methodStatic memberToString(Int16)Converts the Int16 to a String.
Public methodStatic memberToString(Int32)Converts the Int32 to a String.
Public methodStatic memberToString(Int64)Converts the Int64 to a String.
Public methodStatic memberToString(SByte)Converts the SByte to a String.
Public methodStatic memberToString(Single)Converts the Single to a String.
Public methodStatic memberToString(TimeSpan)Converts the TimeSpan to a String.
Public methodStatic memberToString(UInt32)Converts the UInt32 to a String.
Public methodStatic memberToString(UInt64)Converts the UInt64 to a String.
Public methodStatic memberToString(DateTime, XmlDateTimeSerializationMode)Converts the DateTime to a String using the XmlDateTimeSerializationMode specified.
Public methodStatic memberToString(DateTimeOffset, String)Converts the supplied DateTimeOffset to a String in the specified format.
Public methodStatic memberToTimeSpanConverts the String to a TimeSpan equivalent.
Public methodStatic memberToUInt16Converts the String to a UInt16 equivalent.
Public methodStatic memberToUInt32Converts the String to a UInt32 equivalent.
Public methodStatic memberToUInt64Converts the String to a UInt64 equivalent.
Public methodStatic memberVerifyNameVerifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
Public methodStatic memberVerifyNCNameVerifies that the name is a valid NCName according to the W3C Extended Markup Language recommendation.
Public methodStatic memberVerifyNMTOKENVerifies that the string is a valid NMTOKEN according to the W3C XML Schema Part2: Datatypes recommendation
Public methodStatic memberVerifyPublicIdVerifies whether all the character is in the string argument are valid PUBLIC ID characters.
Public methodStatic memberVerifyWhitespaceVerifies whether all the characters in the string argument are valid whitespace characters.
Public methodStatic memberVerifyXmlCharsVerifies if all the characters and surrogate pair characters in the passed in string are valid XML characters.
Top

Element and attribute names or ID values are limited to a range of XML characters according to the Extensible Markup Language (XML) 1.0 (Fourth Edition) recommendation, located at http://www.w3.org/TR/2006/REC-xml-20060816/. When names contain invalid characters, the EncodeName and DecodeName methods are used to translate them into valid XML names.

Many languages and applications such as Microsoft SQL Server and Microsoft Word, 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 EncodeName method can be used with the XmlWriter class to ensure the names being written are valid XML names. The following C# code converts the name 'Order Detail' into a valid XML name and writes the element <Order_0x0020_Detail>My order</Order_0x0020_Detail>.

 writer.WriteElementString(XmlConvert.EncodeName("Order Detail"),"My order");

XmlConvert also provides methods that enable you to convert from a string to a.NET Framework data type and vice-versa. Locale settings are not taken into account during data conversion.

No code example is currently available or this language may not be supported.

Windows Phone OS

Supported in: 8.1, 8.0, 7.1, 7.0

Windows Phone

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Show:
© 2017 Microsoft