다음을 통해 공유


XmlValidatingReader.EntityHandling 속성

정의

판독기가 엔터티를 처리하는 방법을 지정하는 값을 가져오거나 설정합니다.

public:
 property System::Xml::EntityHandling EntityHandling { System::Xml::EntityHandling get(); void set(System::Xml::EntityHandling value); };
public System.Xml.EntityHandling EntityHandling { get; set; }
member this.EntityHandling : System.Xml.EntityHandling with get, set
Public Property EntityHandling As EntityHandling

속성 값

EntityHandling

EntityHandling 값 중 하나입니다. EntityHandling이 지정되지 않으면 기본값은 EntityHandling.ExpandEntities로 지정됩니다.

예외

잘못된 값이 지정된 경우

예제

다음 예제에서는 메서드를 ResolveEntity 사용하여 일반 엔터티를 확장합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlValidatingReader^ reader = nullptr;
   XmlTextReader^ txtreader = nullptr;
   try
   {
      
      //Create and load the XmlTextReader with the XML file. 
      txtreader = gcnew XmlTextReader( "book1.xml" );
      txtreader->WhitespaceHandling = WhitespaceHandling::None;
      
      //Create the XmlValidatingReader over the XmlTextReader.
      //Set the reader to not expand general entities.
      reader = gcnew XmlValidatingReader( txtreader );
      reader->ValidationType = ValidationType::None;
      reader->EntityHandling = EntityHandling::ExpandCharEntities;
      reader->MoveToContent(); //Move to the root element.
      reader->Read(); //Move to title start tag.
      reader->Skip(); //Skip the title element.
      
      //Read the misc start tag.  The reader is now positioned on
      //the entity reference node.
      reader->ReadStartElement();
      
      //Because EntityHandling is set to ExpandCharEntities, you must call 
      //ResolveEntity to expand the entity.  The entity replacement text is 
      //then parsed and returned as a child node.         
      Console::WriteLine( "Expand the entity..." );
      reader->ResolveEntity();
      Console::WriteLine( "The entity replacement text is returned as a text node." );
      reader->Read();
      Console::WriteLine( "NodeType: {0} Value: {1}", reader->NodeType, reader->Value );
      Console::WriteLine( "An EndEntity node closes the entity reference scope." );
      reader->Read();
      Console::WriteLine( "NodeType: {0} Name: {1}", reader->NodeType, reader->Name );
   }
   finally
   {
      if ( reader != nullptr )
            reader->Close();
   }

}

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

public class Sample
{
  public static void Main()
  {
     XmlValidatingReader reader = null;
     XmlTextReader txtreader = null;

     try
     {
       //Create and load the XmlTextReader with the XML file.
       txtreader = new XmlTextReader("book1.xml");
       txtreader.WhitespaceHandling = WhitespaceHandling.None;

       //Create the XmlValidatingReader over the XmlTextReader.
       //Set the reader to not expand general entities.
       reader = new XmlValidatingReader(txtreader);
       reader.ValidationType = ValidationType.None;
       reader.EntityHandling = EntityHandling.ExpandCharEntities;

       reader.MoveToContent();  //Move to the root element.
       reader.Read();  //Move to title start tag.
       reader.Skip();  //Skip the title element.

       //Read the misc start tag.  The reader is now positioned on
       //the entity reference node.
       reader.ReadStartElement();

       //Because EntityHandling is set to ExpandCharEntities, you must call
       //ResolveEntity to expand the entity.  The entity replacement text is
       //then parsed and returned as a child node.
       Console.WriteLine("Expand the entity...");
       reader.ResolveEntity();

       Console.WriteLine("The entity replacement text is returned as a text node.");
       reader.Read();
       Console.WriteLine("NodeType: {0} Value: {1}", reader.NodeType ,reader.Value);

       Console.WriteLine("An EndEntity node closes the entity reference scope.");
       reader.Read();
       Console.WriteLine("NodeType: {0} Name: {1}", reader.NodeType,reader.Name);
    }
    finally
    {
       if (reader != null)
         reader.Close();
    }
  }
}
Option Strict
Option Explicit

Imports System.IO
Imports System.Xml

Public Class Sample
   
   Public Shared Sub Main()
      Dim reader As XmlValidatingReader = Nothing
      Dim txtreader As XmlTextReader = Nothing
      
      Try
         'Create and load the XmlTextReader with the XML file. 
         txtreader = New XmlTextReader("book1.xml")
         txtreader.WhitespaceHandling = WhitespaceHandling.None
         
         'Create the XmlValidatingReader over the XmlTextReader.
         'Set the reader to not expand general entities.
         reader = New XmlValidatingReader(txtreader)
         reader.ValidationType = ValidationType.None
         reader.EntityHandling = EntityHandling.ExpandCharEntities
         
         reader.MoveToContent() 'Move to the root element.
         reader.Read() 'Move to title start tag.
         reader.Skip() 'Skip the title element.
         'Read the misc start tag.  The reader is now positioned on
         'the entity reference node.
         reader.ReadStartElement()
         
         'Because EntityHandling is set to ExpandCharEntities, you must call 
         'ResolveEntity to expand the entity.  The entity replacement text is 
         'then parsed and returned as a child node.  
         Console.WriteLine("Expand the entity...")
         reader.ResolveEntity()
         
         Console.WriteLine("The entity replacement text is returned as a text node.")
         reader.Read()
         Console.WriteLine("NodeType: {0} Value: {1}", reader.NodeType, reader.Value)
         
         Console.WriteLine("An EndEntity node closes the entity reference scope.")
         reader.Read()
         Console.WriteLine("NodeType: {0} Name: {1}", reader.NodeType, reader.Name)
      
      Finally
         If Not (reader Is Nothing) Then
            reader.Close()
         End If
      End Try
   End Sub
End Class

이 예제에서는 파일을 book1.xml입력으로 사용합니다.


<?xml version='1.0' ?>
<!DOCTYPE book [<!ENTITY h 'hardcover'>]>
<book>
  <title>Pride And Prejudice</title>
  <misc>&h;</misc>
</book>

설명

참고

클래스는 XmlValidatingReader .NET Framework 2.0에서 사용되지 않습니다. 클래스 및 메서드를 사용하여 유효성 XmlReader 검사 인스턴스를 XmlReaderSettings Create 만들 수 있습니다. 자세한 내용은 XmlReader 참조 페이지의 설명 섹션을 참조하세요.

이 속성은 변경할 수 있으며 다음 Read 호출 후에 적용됩니다.

EntityHandling 설정ExpandCharEntities하면 특성 값이 부분적으로만 정규화됩니다. 판독기는 인접한 엔터티 참조 노드의 콘텐츠와 독립적으로 각 개별 텍스트 노드를 정규화합니다.

엔터티 처리 모드 간의 차이점을 설명하기 위해 다음 XML을 고려합니다.

<!DOCTYPE doc [<!ENTITY num "123">]>  
 <doc> &#65; &num; </doc>  

"doc" 요소 노드로 ExpandEntities 설정된 경우 EntityHandling 확장된 엔터티 텍스트가 있는 하나의 텍스트 노드가 포함됩니다.

깊이 노드 형식 Name
1 텍스트 A 123

이 값으로 ExpandCharEntities설정되고 WhitespaceHandling Significant 또는 All로 설정된 경우 EntityHandling "doc" 요소는 문자 엔터티를 확장하고 일반 엔터티를 노드로 반환합니다.

깊이 노드 형식 Name
1 텍스트 A
1 EntityReference num
1 SignificantWhitespace

적용 대상

추가 정보