Share via


XmlNodeReader.HasValue Proprietà

Definizione

Ottiene un valore che indica se il nodo corrente può presentare una proprietà Value.

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

Valore della proprietà

true se il nodo sul quale il lettore è attualmente posizionato può contenere Value; in caso contrario, false.

Esempio

Nell'esempio seguente viene visualizzato il valore per ogni nodo che può avere un valore.

#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

Commenti

Nota

In .NET Framework 2.0, la procedura consigliata consiste nel creare XmlReader istanze usando la XmlReaderSettings classe e il Create metodo . In questo modo è possibile sfruttare appieno tutte le nuove funzionalità introdotte in .NET Framework. Per altre informazioni, vedere la sezione Osservazioni nella pagina di XmlReader riferimento.

La tabella seguente elenca i tipi di nodo che hanno un valore da restituire.

Tipo di nodo Valore
Attribute Valore dell'attributo.
CDATA Contenuto della sezione CDATA.
Comment Contenuto del commento.
DocumentType Sottoinsieme interno.
ProcessingInstruction Intero contenuto, esclusa la destinazione.
SignificantWhitespace Spazio vuoto tra markup in un modello con contenuto misto.
Text Contenuto del nodo di tipo text.
Whitespace Spazio vuoto tra markup.
XmlDeclaration Contenuto della dichiarazione.

Si applica a