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

속성 값

Boolean

정규화하려면 true이고, 그렇지 않으면 false입니다. 기본값은 false입니다.

예외

판독기를 닫은 상태에서 이 속성을 설정하는 경우(ReadStateReadState.Closed인 경우)

예제

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

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create the XML fragment to be parsed.
   String^ xmlFrag = "<item attr1='  test A B C\n"
   "1 2 3'/>\n"
   "<item attr2=''/>\n";
   
   // Create the XmlNamespaceManager.
   XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager( gcnew NameTable );
   
   // Create the XmlParserContext.
   XmlParserContext^ context = gcnew XmlParserContext( nullptr,nsmgr,nullptr,XmlSpace::Preserve );
   
   // Create the reader.
   XmlTextReader^ reader = gcnew 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();
}
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

설명

참고

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

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

참고

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

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

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

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

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

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

  • 표준화된 값에 기타 문자를 추가하여 처리합니다.

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

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

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

적용 대상

추가 정보