Assembly: System.Xml (in system.xml.dll)
Public Overrides ReadOnly Property HasValue As Boolean
Dim instance As XmlTextReader Dim value As Boolean value = instance.HasValue
public override bool HasValue { get; }
public: virtual property bool HasValue { bool get () override; }
/** @property */ public boolean get_HasValue ()
public override function get HasValue () : boolean
Valore proprietà
true se il nodo sul quale il visualizzatore è attualmente posizionato può presentare una proprietà Value, in caso contrario false. Nota |
|---|
| Nella versione Microsoft .NET Framework versione 2.0 è consigliabile creare istanze di XmlReader utilizzando il metodo System.Xml.XmlReader.Create. In questo modo è possibile sfruttare completamente le nuove funzionalità introdotte in questa versione. Per ulteriori informazioni, vedere Creazione di lettori XML. |
Nella tabella seguente sono elencati i tipi di nodo che possono restituire un valore.
| Tipo di nodo | Valore |
|---|---|
| Attribute | Valore dell'attributo. |
| CDATA | Contenuto della sezione CDATA. |
| Comment | Contenuto del commento. |
| DocumentType | Sottoinsieme interno. |
| ProcessingInstruction | Intero contenuto, ad eccezione della destinazione. |
| SignificantWhitespace | Spazio tra parti di codice in un modello a contenuto misto. |
| Text | Contenuto del nodo testo. |
| Whitespace | Spazio vuoto tra parti di codice. |
| XmlDeclaration | Contenuto della dichiarazione. |
Nell'esempio che segue viene visualizzato il valore di ciascun nodo che può presentare un valore.
Imports System 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 'Main End Class 'Sample
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
#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(); } }
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
XmlTextReader reader = null;
try {
//Load the reader with the XML file.
reader = new XmlTextReader("book1.xml");
reader.set_WhitespaceHandling(WhitespaceHandling.None);
//Parse the file and display each node.
while (reader.Read()) {
if (reader.get_HasValue()) {
Console.WriteLine("({0}) {1}={2}", reader.get_NodeType(),
reader.get_Name(), reader.get_Value());
}
else {
Console.WriteLine("({0}) {1}", reader.get_NodeType(),
reader.get_Name());
}
}
}
finally {
if (reader != null) {
reader.Close();
}
}
} //main
} // End class Sample
Nell'esempio viene utilizzato il file book1.xml come input.
<?xml version='1.0' ?> <!DOCTYPE book [<!ENTITY h 'hardcover'>]> <book> <title>Pride And Prejudice</title> <misc>&h;</misc> </book>
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework non supporta tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema.
.NET Framework
Supportato in: 2.0 1.1 1.0.NET Compact Framework
Supportato in: 2.0 1.0Riferimenti
Classe XmlTextReaderMembri XmlTextReader
Spazio dei nomi System.Xml
Nota