XmlDeclaration.Encoding XmlDeclaration.Encoding XmlDeclaration.Encoding XmlDeclaration.Encoding Property

정의

XML 문서의 인코딩 수준을 가져오거나 설정합니다.Gets or sets the encoding level of the XML document.

public:
 property System::String ^ Encoding { System::String ^ get(); void set(System::String ^ value); };
public string Encoding { get; set; }
member this.Encoding : string with get, set
Public Property Encoding As String

속성 값

올바른 문자 인코딩 이름입니다.The valid character encoding name. 다음은 가장 일반적으로 지원되는 XML 문자 인코딩 이름입니다.The most commonly supported character encoding names for XML are the following:

범주Category 인코딩 이름Encoding Names
유니코드(Unicode)Unicode UTF-8, UTF-16UTF-8, UTF-16
ISO 10646ISO 10646 ISO-10646-UCS-2, ISO-10646-UCS-4ISO-10646-UCS-2, ISO-10646-UCS-4
ISO 8859ISO 8859 ISO-8859-n(여기서 "n"은 1에서 9 사이의 숫자임)ISO-8859-n (where "n" is a digit from 1 to 9)
JIS X-0208-1997JIS X-0208-1997 ISO-2022-JP, Shift_JIS, EUC-JPISO-2022-JP, Shift_JIS, EUC-JP

이 값은 선택 사항입니다.This value is optional. 값이 설정되지 않으면 이 속성은 String.Empty를 반환합니다.If a value is not set, this property returns String.Empty.

인코딩 속성이 포함되지 않으면 문서를 쓰거나 저장할 때 UTF-8 인코딩을 가정합니다.If an encoding attribute is not included, UTF-8 encoding is assumed when the document is written or saved out.

예제

다음 예제에서는 XmlDeclaration 노드 XML 문서에 추가 합니다.The following example creates an XmlDeclaration node and adds it to an XML document.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create and load the XML document.
   XmlDocument^ doc = gcnew XmlDocument;
   String^ xmlString = "<book><title>Oberon's Legacy</title></book>";
   doc->Load( gcnew StringReader( xmlString ) );
   
   // Create an XML declaration. 
   XmlDeclaration^ xmldecl;
   xmldecl = doc->CreateXmlDeclaration( "1.0", nullptr, nullptr );
   xmldecl->Encoding = "UTF-8";
   xmldecl->Standalone = "yes";
   
   // Add the new node to the document.
   XmlElement^ root = doc->DocumentElement;
   doc->InsertBefore( xmldecl, root );
   
   // Display the modified XML document 
   Console::WriteLine( doc->OuterXml );
}

using System;
using System.IO;
using System.Xml;
 
public class Sample {

  public static void Main() {
   
    // Create and load the XML document.
    XmlDocument doc = new XmlDocument();
    string xmlString = "<book><title>Oberon's Legacy</title></book>";
    doc.Load(new StringReader(xmlString));
  
    // Create an XML declaration. 
    XmlDeclaration xmldecl;
    xmldecl = doc.CreateXmlDeclaration("1.0",null,null);
    xmldecl.Encoding="UTF-8";
    xmldecl.Standalone="yes";     
      
    // Add the new node to the document.
    XmlElement root = doc.DocumentElement;
    doc.InsertBefore(xmldecl, root);
    
    // Display the modified XML document 
    Console.WriteLine(doc.OuterXml);
      
  }
}
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main() 
   
    ' Create and load the XML document.
    Dim doc as XmlDocument = new XmlDocument()
    Dim xmlString as string = "<book><title>Oberon's Legacy</title></book>"
    doc.Load(new StringReader(xmlString))
  
    ' Create an XML declaration. 
    Dim xmldecl as XmlDeclaration 
    xmldecl = doc.CreateXmlDeclaration("1.0",nothing, nothing)
    xmldecl.Encoding="UTF-8"
    xmldecl.Standalone="yes"     
      
    ' Add the new node to the document.
    Dim root as XmlElement = doc.DocumentElement
    doc.InsertBefore(xmldecl, root)
    
    ' Display the modified XML document 
    Console.WriteLine(doc.OuterXml)
      
  end sub
end class

설명

대부분의 XML 특성과 달리 인코딩 특성 값은 대/소문자 구분 되지 않습니다.Unlike most XML attributes, encoding attribute values are not case-sensitive. 인코딩 문자 이름을 IANA Internet Assigned Numbers Authority () 및 ISO 표준에 따라 때문입니다.This is because encoding character names follow ISO and Internet Assigned Numbers Authority (IANA) standards.

적용 대상