Прочетете на английски Редактиране

Споделяне чрез


XmlConvert.EncodeLocalName(String) Method

Definition

Converts the name to a valid XML local name.

C#
public static string EncodeLocalName(string name);
C#
public static string? EncodeLocalName(string? name);

Parameters

name
String

The name to be encoded.

Returns

The encoded name.

Examples

The following example encodes and decodes names.

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

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 null or System.String.Empty, the method returns the same value.

Applies to

Продукт Версии
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.0, 1.1, 1.2, 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

See also