System.Xml.XmlConvert.EncodeLocalName Method

Converts the name to a valid XML local name.

Syntax

public static string EncodeLocalName (string name)

Parameters

name
The name to be encoded.

Returns

The encoded name.

Remarks

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.

Example

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_

Requirements

Namespace: System.Xml
Assembly: System.Xml (in System.Xml.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0