The encoded name.
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.
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 null or String.Empty then you get the same value returned.
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_