XmlTextReader.HasValue 속성

정의

현재 노드에 String.Empty 이외의 Value를 사용할 수 있는지를 나타내는 값을 가져옵니다.

public:
 virtual property bool HasValue { bool get(); };
public override bool HasValue { get; }
member this.HasValue : bool
Public Overrides ReadOnly Property HasValue As Boolean

속성 값

Boolean

현재 판독기가 위치한 노드에 Value가 있으면 true이고, 그렇지 않으면 false입니다.

예제

다음 예제에서는 값을 가질 수 있는 모든 노드의 값을 표시합니다.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlTextReader^ reader = nullptr;
   try
   {
      
      //Load the reader with the XML file.
      reader = gcnew XmlTextReader( "book1.xml" );
      reader->WhitespaceHandling = WhitespaceHandling::None;
      
      //Parse the file and display each node.
      while ( reader->Read() )
      {
         if ( reader->HasValue )
                  Console::WriteLine( "({0})  {1}={2}", reader->NodeType, reader->Name, reader->Value );
         else
                  Console::WriteLine( "({0}) {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()
  {
    XmlTextReader reader = null;

    try
    {
        //Load the reader with the XML file.
        reader = new XmlTextReader("book1.xml");
        reader.WhitespaceHandling = WhitespaceHandling.None;

        //Parse the file and display each node.
        while (reader.Read())
        {
           if (reader.HasValue)
             Console.WriteLine("({0})  {1}={2}", reader.NodeType, reader.Name, reader.Value);
           else
             Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name);
         }
     }

     finally
     {
       if (reader!=null)
         reader.Close();
     }
  }
} // End class
Imports System.IO
Imports System.Xml

Public Class Sample
    
    Public Shared Sub Main()
        Dim reader As XmlTextReader = Nothing
        
        Try
            'Load the reader with the XML file.
            reader = New XmlTextReader("book1.xml")
            reader.WhitespaceHandling = WhitespaceHandling.None
            
            'Parse the file and display each node.
            While reader.Read()
                If reader.HasValue Then
                    Console.WriteLine("({0})  {1}={2}", reader.NodeType, reader.Name, reader.Value)
                Else
                    Console.WriteLine("({0}) {1}", reader.NodeType, reader.Name)
                End If
            End While
        
        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>

설명

참고

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

다음 표에서는 반환할 값이 있는 노드 형식을 보여 줍니다.

노드 형식
Attribute 특성 값
CDATA CDATA 섹션 내용입니다.
Comment 주석의 내용입니다.
DocumentType 내부 하위 집합입니다.
ProcessingInstruction 대상을 제외한 전체 내용입니다.
SignificantWhitespace 혼합된 콘텐츠 모델의 태그 간 공백입니다.
Text 텍스트 노드의 내용입니다.
Whitespace 태그 사이의 공백입니다.
XmlDeclaration 선언 내용입니다.

적용 대상

추가 정보