XmlTextReader.Normalization 속성

정의

공백 및 특성 값을 정규화할지 여부를 나타내는 값을 가져오거나 설정합니다.

public:
 property bool Normalization { bool get(); void set(bool value); };
public bool Normalization { get; set; }
member this.Normalization : bool with get, set
Public Property Normalization As Boolean

속성 값

true를 정규화합니다. 그렇지 않으면 . false 기본값은 false입니다.

예외

판독기를 닫을 때 이 속성 설정(ReadState is)입니다 ReadState.Closed.

예제

다음 예제에서는 정규화가 켜진 다음 꺼진 판독기 동작을 보여 집니다.

using System;
using System.IO;
using System.Xml;

public class Sample{

  public static void Main(){

    // Create the XML fragment to be parsed.
    string xmlFrag  =
    @"<item attr1='  test A B C
        1 2 3'/>
      <item attr2=''/>";

    // Create the XmlNamespaceManager.
    XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable());

    // Create the XmlParserContext.
    XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.Preserve);

    // Create the reader.
    XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);

    // Show attribute value normalization.
    reader.Read();
    reader.Normalization = false;
    Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"));
    reader.Normalization = true;
    Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"));

    // Set Normalization back to false.  This allows the reader to accept
    // character entities in the � to  range.  If Normalization had
    // been set to true, character entities in this range throw an exception.
    reader.Normalization = false;
    reader.Read();
    reader.MoveToContent();
    Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr2"));

    // Close the reader.
    reader.Close();
  }
}
Imports System.IO
Imports System.Xml

public class Sample

  public shared sub Main()

    ' Create the XML fragment to be parsed.
    Dim xmlFrag as string = "<item attr1='  test A B C " + Chr(10) & _
                            "   1 2 3'/>" + Chr(10) & _
                            "<item attr2=''/>"
                    

    ' Create the XmlNamespaceManager.
    Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(new NameTable())

    ' Create the XmlParserContext.
    Dim context as XmlParserContext = new XmlParserContext(nothing, nsmgr, nothing, XmlSpace.Preserve)

    ' Create the reader.
    Dim reader as XmlTextReader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context)

    ' Show attribute value normalization.
    reader.Read()
    reader.Normalization = false
    Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"))
    reader.Normalization = true
    Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"))

    ' Set Normalization back to false.  This allows the reader to accept
    ' character entities in the � to  range.  If Normalization had
    ' been set to true, character entities in this range throw an exception.
    reader.Normalization = false
    reader.Read()
    reader.MoveToContent()
    Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr2"))
  
    ' Close the reader.
    reader.Close()     
  
  end sub
end class

설명

메모

새 기능을 활용하기 위해 XmlReader 메서드를 사용하여 XmlReader.Create 인스턴스를 만드는 것이 좋습니다.

이 속성은 언제든지 변경할 수 있으며 다음 읽기 작업에 적용됩니다.

메모

XmlTextReader 특성 값을 Normalization 정규화하기 위해 XmlValidatingReader를 생성하는 데 사용되는 경우 다음으로 true설정해야 합니다.

이 값으로 false설정하면 Normalization 숫자 엔터티에 대한 문자 범위 검사도 사용하지 않도록 설정됩니다. 따라서 문자 엔터티(예: &#0;)가 허용됩니다.

다음은 특성 값 정규화에 대해 설명합니다.

  • 문자 참조의 경우 참조된 문자를 특성 값에 추가합니다.

  • 엔터티 참조의 경우 엔터티의 대체 텍스트를 재귀적으로 처리합니다.

  • 공백 문자(#x20, #xD, #xA, #x9)의 경우 정규화된 값에 #x20 추가합니다. (외부 구문 분석된 엔터티의 일부인 "#xD#xA" 시퀀스 또는 내부 구문 분석된 엔터티의 리터럴 엔터티 값에는 단일 #x20 추가됩니다.

  • 다른 문자를 정규화된 값에 추가하여 처리합니다.

  • 선언된 값이 CDATA가 아닌 경우 선행 및 후행 공백(#x20) 문자를 삭제하고 공백(#x20) 문자 시퀀스를 단일 공백(#x20) 문자로 바꿉니다.

XmlTextReader 특성 또는 CDATA 정규화만 수행합니다. 에 래핑되지 않는 한 DTD 관련 정규화는 XmlValidatingReader수행되지 않습니다.

정규화에 대한 자세한 내용은 W3C XML 1.0 권장 사항을 참조하세요.

적용 대상

추가 정보