.NET Framework Class Library
XmlConvert..::.DecodeName Method

Decodes a name. This method does the reverse of the EncodeName and EncodeLocalName methods.

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

Visual Basic (Declaration)
Public Shared Function DecodeName ( _
    name As String _
) As String
Visual Basic (Usage)
Dim name As String
Dim returnValue As String

returnValue = XmlConvert.DecodeName(name)
C#
public static string DecodeName(
    string name
)
Visual C++
public:
static String^ DecodeName(
    String^ name
)
JScript
public static function DecodeName(
    name : String
) : String

Parameters

name
Type: System..::.String
The name to be transformed.

Return Value

Type: System..::.String
The decoded name.
Remarks

The names are decoded using the following rules:

  • Names are decoded from left to right.

  • Any sequence _x HHHH_ (where HHHH stands for a valid, four digit hexadecimal UCS-2 code) that has not been decoded is transformed into the corresponding Unicode 2.1 (Unicode 3.0 if supported by the application) character.

  • No shortforms are recognized. They are passed on without translation. For example, _x20_ or __ are not decoded.

NoteNote:

The actual encoding of the character is application-specific. For example, Order_x0020_Details becomes Order Details. Even escaped characters that are invalid in XML names will be recognized and decoded.

Examples

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));

  }
}
Visual C++
#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( "Order Detail" );
   Console::WriteLine( "Encoded name: {0}", name1 );
   Console::WriteLine( "Decoded name: {0}", XmlConvert::DecodeName( name1 ) );

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

CPP_OLD
#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));
}
Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
See Also

Reference

Tags :


Page view tracker