Export (0) Print
Expand All
2 out of 2 rated this helpful - Rate this topic

XmlConvert Class

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.

System.Object
  System.Xml.XmlConvert

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)
public class XmlConvert

The XmlConvert type exposes the following members.

  NameDescription
Public methodSupported by the XNA FrameworkXmlConvertInitializes a new instance of the XmlConvert class.
Top
  NameDescription
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryDecodeNameDecodes a name. This method does the reverse of the EncodeName and EncodeLocalName methods.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryEncodeLocalNameConverts the name to a valid XML local name.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryEncodeNameConverts the name to a valid XML name.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryEncodeNmTokenVerifies the name is valid according to the XML specification.
Public methodSupported by the XNA FrameworkEquals(Object)Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected methodSupported by the XNA FrameworkFinalizeAllows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public methodStatic memberSupported by the XNA FrameworkFromBinHexString Obsolete. Converts a BinHex-encoded string to a byte array.
Public methodSupported by the XNA FrameworkGetHashCodeServes as a hash function for a particular type. (Inherited from Object.)
Public methodSupported by the XNA FrameworkGetTypeGets the Type of the current instance. (Inherited from Object.)
Public methodStatic memberSupported by Portable Class LibraryIsNCNameCharChecks whether the passed-in character is a valid non-colon character type.
Public methodStatic memberIsPublicIdCharReturns the passed-in character instance if the character in the argument is a valid public id character, otherwise null.
Public methodStatic memberSupported by Portable Class LibraryIsStartNCNameCharChecks 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 methodSupported by the XNA FrameworkMemberwiseCloneCreates a shallow copy of the current Object. (Inherited from Object.)
Public methodStatic memberSupported by the XNA FrameworkToBinHexString Obsolete. Converts a byte array to a BinHex-encoded string.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToBooleanConverts the String to a Boolean equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToByteConverts the String to a Byte equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToCharConverts the String to a Char equivalent.
Public methodStatic memberSupported by the XNA FrameworkToDateTime(String) Obsolete. Converts the String to a DateTime equivalent.
Public methodStatic memberSupported by the XNA FrameworkToDateTime(String, String)Converts the String to a DateTime equivalent.
Public methodStatic memberSupported by the XNA FrameworkToDateTime(String, String[])Converts the String to a DateTime equivalent.
Public methodStatic memberSupported by the XNA FrameworkToDateTime(String, XmlDateTimeSerializationMode)Converts the String to a DateTime using the XmlDateTimeSerializationMode specified
Public methodStatic memberSupported by Portable Class LibraryToDateTimeOffset(String)Converts the supplied String to a DateTimeOffset equivalent.
Public methodStatic memberSupported by Portable Class LibraryToDateTimeOffset(String, String)Converts the supplied String to a DateTimeOffset equivalent.
Public methodStatic memberSupported by Portable Class LibraryToDateTimeOffset(String, String[])Converts the supplied String to a DateTimeOffset equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToDecimalConverts the String to a Decimal equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToDoubleConverts the String to a Double equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToGuidConverts the String to a Guid equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToInt16Converts the String to a Int16 equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToInt32Converts the String to a Int32 equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToInt64Converts the String to a Int64 equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToSByteConverts the String to a SByte equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToSingleConverts the String to a Single equivalent.
Public methodSupported by the XNA FrameworkToString()Returns a string that represents the current object. (Inherited from Object.)
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Boolean)Converts the Boolean to a String.
Public methodStatic memberSupported by the XNA FrameworkToString(Byte)Converts the Byte to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Char)Converts the Char to a String.
Public methodStatic memberSupported by the XNA FrameworkToString(DateTime) Obsolete. Converts the DateTime to a String.
Public methodStatic memberSupported by Portable Class LibraryToString(DateTimeOffset)Converts the supplied DateTimeOffset to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Decimal)Converts the Decimal to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Double)Converts the Double to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Guid)Converts the Guid to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Int16)Converts the Int16 to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Int32)Converts the Int32 to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Int64)Converts the Int64 to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(SByte)Converts the SByte to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(Single)Converts the Single to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(TimeSpan)Converts the TimeSpan to a String.
Public methodStatic memberSupported by the XNA FrameworkToString(UInt16)Converts the UInt16 to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(UInt32)Converts the UInt32 to a String.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToString(UInt64)Converts the UInt64 to a String.
Public methodStatic memberSupported by the XNA FrameworkToString(DateTime, String)Converts the DateTime to a String.
Public methodStatic memberSupported by the XNA FrameworkToString(DateTime, XmlDateTimeSerializationMode)Converts the DateTime to a String using the XmlDateTimeSerializationMode specified.
Public methodStatic memberSupported by Portable Class LibraryToString(DateTimeOffset, String)Converts the supplied DateTimeOffset to a String in the specified format.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToTimeSpanConverts the String to a TimeSpan equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToUInt16Converts the String to a UInt16 equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToUInt32Converts the String to a UInt32 equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryToUInt64Converts the String to a UInt64 equivalent.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryVerifyNameVerifies that the name is a valid name according to the W3C Extended Markup Language recommendation.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryVerifyNCNameVerifies that the name is a valid NCName according to the W3C Extended Markup Language recommendation. An NCName is a name that cannot contain a colon.
Public methodStatic memberSupported by the XNA FrameworkSupported by Portable Class LibraryVerifyNMTOKENVerifies that the string is a valid NMTOKEN according to the W3C XML Schema Part2: Datatypes recommendation
Public methodStatic memberSupported by Portable Class LibraryVerifyPublicIdReturns the passed in string instance if all the characters in the string argument are valid public id characters.
Public methodStatic memberSupported by the XNA FrameworkVerifyTOKENVerifies that the string is a valid token according to the W3C XML Schema Part2: Datatypes recommendation.
Public methodStatic memberSupported by Portable Class LibraryVerifyWhitespaceReturns the passed-in string instance if all the characters in the string argument are valid whitespace characters.
Public methodStatic memberSupported by Portable Class LibraryVerifyXmlCharsReturns the passed-in string if all the characters and surrogate pair characters in the string argument are valid XML characters, otherwise null.
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 spec (Fourth Edition) recommendation. 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. The data types are based on the XML Schema (XSD) data types.

NoteNote

In the .NET Framework version 2.0, the XmlReader, XmlWriter, and XPathNavigator classes include new methods that can handle typed data. These new methods handle the string to .NET Framework data type conversion for you.

.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.