Click to Rate and Give Feedback
MSDN
MSDN Library
.NET Development
Previous Versions
.NET Framework 1.1
.NET Framework
Reference
System.Xml
XmlConvert Class
Methods
 EncodeLocalName Method

  Switch on low bandwidth view
This page is specific to
Microsoft Visual Studio 2003/.NET Framework 1.1

Other versions are also available for the following:
.NET Framework Class Library
XmlConvert.EncodeLocalName Method

Converts the name to a valid XML local name.

[Visual Basic]
Public Shared Function EncodeLocalName( _
   ByVal name As String _
) As String
[C#]
public static string EncodeLocalName(
 string name
);
[C++]
public: static String* EncodeLocalName(
 String* name
);
[JScript]
public static function EncodeLocalName(
   name : String
) : String;

Parameters

name
The name to be encoded.

Return Value

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 a null reference (Nothing in Visual Basic) or String.Empty then you get the same value returned.

Example

[Visual Basic, C#, C++] The following example encodes and decodes names.

[Visual Basic] 
Imports System
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

     ' Encode and decode a name with spaces.
     Dim name1 as string = XmlConvert.EncodeName("Order Detail")
     Console.WriteLine("Encoded name: " + name1)
     Console.WriteLine("Decoded name: " + XmlConvert.DecodeName(name1))

     ' Encode and decode a local name.
     Dim name2 as string= XmlConvert.EncodeLocalName("a:book")
     Console.WriteLine("Encoded local name: " + name2)
     Console.WriteLine("Decoded local name: " + XmlConvert.DecodeName(name2))

  end sub
end class

[C#] 
using System;
using System.IO;
using System.Xml;

public class Sample
{

  public static void Main()
  {

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

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

  }
}

[C++] 

#using <mscorlib.dll>
#using <System.dll>
#using <System.XML.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;

int main()
{
   // Encode and decode a name with spaces.
   String* name1 = XmlConvert::EncodeName(S"Order Detail");
   Console::WriteLine( S"Encoded name: {0}", name1);
   Console::WriteLine( S"Decoded name: {0}", XmlConvert::DecodeName(name1));

   // Encode and decode a local name.
   String*    name2 = XmlConvert::EncodeLocalName(S"a:book");
   Console::WriteLine( S"Encoded local name: {0}", name2);
   Console::WriteLine( S"Decoded local name: {0}", XmlConvert::DecodeName(name2));
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

XmlConvert Class | XmlConvert Members | System.Xml Namespace | EncodeName | DecodeName

© 2009 Microsoft Corporation. All rights reserved. Terms of Use  |  Trademarks  |  Privacy Statement
Page view tracker