XmlTextReader.HasValue Vlastnost

Definice

Získá hodnotu určující, zda aktuální uzel může mít Value jiný než String.Empty.

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

Hodnota vlastnosti

Boolean

true pokud uzel, na kterém je čtenář aktuálně umístěn, může mít ; Valuev opačném případě false.

Příklady

Následující příklad zobrazí hodnotu pro každý uzel, který může mít hodnotu.

#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

Příklad používá soubor , book1.xmljako vstup.


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

Poznámky

Poznámka

Počínaje rozhraním .NET Framework 2.0 doporučujeme vytvářet XmlReader instance pomocí XmlReader.Create metody, abyste mohli využívat nové funkce.

Následující tabulka uvádí typy uzlů, které mají hodnotu, která se má vrátit.

Typ uzlu Hodnota
Attribute Hodnota atributu.
CDATA Obsah oddílu CDATA
Comment Obsah komentáře.
DocumentType Interní podmnožina.
ProcessingInstruction Celý obsah s výjimkou cíle.
SignificantWhitespace Prázdné znaky mezi značkami v modelu smíšeného obsahu
Text Obsah textového uzlu
Whitespace Prázdné znaky mezi značkami
XmlDeclaration Obsah deklarace.

Platí pro

Viz také