Udostępnij za pośrednictwem


XmlConvert.EncodeLocalName Method

Microsoft Silverlight will reach end of support after October 2021. Learn more.

Converts the name to a valid XML local name.

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

Syntax

'Declaration
Public Shared Function EncodeLocalName ( _
    name As String _
) As String
public static string EncodeLocalName(
    string name
)

Parameters

Return Value

Type: System.String
The encoded name.

Remarks

This method is similar to the EncodeName 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.

For example, if you passed this method the invalid name a:b, it returns a_x003a_b, which is a valid local name.

If name is nulla null reference (Nothing in Visual Basic) or String.Empty then you get the same value returned.

Examples

Dim output As New StringBuilder()
' Encode and decode a name with spaces.
Dim name1 As String = XmlConvert.EncodeName("Order Detail")
output.AppendLine("Encoded name: " + name1)
output.AppendLine("Decoded name: " + XmlConvert.DecodeName(name1))

' Encode and decode a local name.
Dim name2 As String = XmlConvert.EncodeLocalName("a:book")
output.AppendLine("Encoded local name: " + name2)
output.AppendLine("Decoded local name: " + XmlConvert.DecodeName(name2))

' Display the output to the TextBlock control
OutputTextBlock.Text = output.ToString()

StringBuilder output = new StringBuilder();
// Encode and decode a name with spaces.
string name1 = XmlConvert.EncodeName("Order Detail");
output.AppendLine("Encoded name: " + name1 );
output.AppendLine("Decoded name: " + XmlConvert.DecodeName(name1));

// Encode and decode a local name.
string name2 = XmlConvert.EncodeLocalName("a:book");
output.AppendLine("Encoded local name: " + name2);
output.AppendLine("Decoded local name: " + XmlConvert.DecodeName(name2));

// Display the output to the TextBlock control
OutputTextBlock.Text = output.ToString();

Version Information

Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1, Windows Phone OS 7.0

XNA Framework

Supported in: Xbox 360, Windows Phone OS 7.0

Platforms

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.