XmlNodeReader.HasValue Propriedade

Definição

Obtém um valor que indica se o nó atual pode ter um Value.

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

Valor da propriedade

true se o nó em que o leitor está posicionado no momento puder ter um Value, caso contrário, false.

Exemplos

O exemplo a seguir exibe o valor de cada nó que pode ter um valor.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   XmlNodeReader^ reader = nullptr;
   try
   {
      
      // Create and load an XmlDocument.
      XmlDocument^ doc = gcnew XmlDocument;
      doc->LoadXml( "<?xml version='1.0' ?>"
      "<!DOCTYPE book [<!ENTITY h 'hardcover'>]>"
      "<book>"
      "<title>Pride And Prejudice</title>"
      "<misc>&h;</misc>"
      "</book>" );
      reader = gcnew XmlNodeReader( doc );
      
      // 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() {

    XmlNodeReader reader = null;

    try {

        // Create and load an XmlDocument.
        XmlDocument doc = new XmlDocument();
        doc.LoadXml("<?xml version='1.0' ?>" +
                    "<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" +
                    "<book>" +
                    "<title>Pride And Prejudice</title>" +
                    "<misc>&h;</misc>" +
                    "</book>");

        reader = new XmlNodeReader(doc);

        // 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
Option Explicit
Option Strict

Imports System.IO
Imports System.Xml

Public Class Sample
    Public Shared Sub Main()
        Dim reader As XmlNodeReader = Nothing
        
        Try
            'Create and load an XmlDocument.
            Dim doc As New XmlDocument()
            doc.LoadXml("<?xml version='1.0' ?>" & _
                        "<!DOCTYPE book [<!ENTITY h 'hardcover'>]>" & _
                        "<book>" & _
                        "<title>Pride And Prejudice</title>" & _
                        "<misc>&h;</misc>" & _
                        "</book>")
            
            reader = New XmlNodeReader(doc)
            
            '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

Comentários

Observação

No .NET Framework 2.0, a prática recomendada é criar XmlReader instâncias usando a XmlReaderSettings classe e o Create método . Isso permite que você aproveite ao máximo todos os novos recursos introduzidos no .NET Framework. Para obter mais informações, consulte a seção Comentários na XmlReader página de referência.

A tabela a seguir lista os tipos de nós que têm um valor a ser retornado.

Tipo de nó Valor
Attribute O valor do atributo.
CDATA O conteúdo da seção CDATA.
Comment O conteúdo do comentário.
DocumentType O subconjunto interno.
ProcessingInstruction Todo o conteúdo, exceto o destino.
SignificantWhitespace Espaço em branco entre marcação em um modelo de conteúdo misto.
Text O conteúdo do nó de texto.
Whitespace Espaço em branco entre a marcação.
XmlDeclaration O conteúdo da declaração.

Aplica-se a