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 is null or string.Empty, name is returned.
This method is similar to the XmlConvert.EncodeName(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 XmlConvert.EncodeLocalName(string), XmlConvert.EncodeName(string), and XmlConvert.EncodeNmToken(string) methods when the name to be encoded is "7:+".
C# Example
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 is
LocalName _x0037__x003A__x002B_
Name _x0037_:_x002B_
NmToken 7:_x002B_
Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0