Assembly: System.Xml (in system.xml.dll)
Public Overrides Function ReadAttributeValue As Boolean
Dim instance As XmlTextReader Dim returnValue As Boolean returnValue = instance.ReadAttributeValue
public override bool ReadAttributeValue ()
public: virtual bool ReadAttributeValue () override
public boolean ReadAttributeValue ()
public override function ReadAttributeValue () : boolean
Valore restituito
true se sono presenti nodi da restituire. false se il visualizzatore non è posizionato in corrispondenza del nodo attributo quando viene effettuata la chiamata iniziale oppure se è stato letto il valore di tutti gli attributi. Un attributo vuoto, quale misc="", restituisce il valore true con un singolo nodo il cui valore è String.Empty. 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. |
Utilizzare questo metodo dopo aver chiamato il metodo MoveToAttribute per leggere i nodi testo o riferimento a entità che costituiscono il valore dell'attributo. La proprietà Depth dei nodi valore attributo corrisponde a uno (1) più la profondità del nodo attributo; tale valore viene incrementato o decrementato di una unità quando si esegue o si esce da un'istruzione dei riferimenti a entità generali.
Nell'esempio seguente viene letto un attributo con nodi testo ed entità.
Imports System Imports System.IO Imports System.Xml public class Sample public shared sub Main() Dim reader as XmlTextReader = nothing try 'Create the XML fragment to be parsed. Dim xmlFrag as string ="<book genre='novel' misc='sale-item &h; 1987'></book>" 'Create the XmlParserContext. Dim context as XmlParserContext Dim subset as string = "<!ENTITY h 'hardcover'>" context = new XmlParserContext(nothing, nothing, "book", nothing, nothing, subset, "", "", XmlSpace.None) 'Create the reader. reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context) 'Read the misc attribute. The attribute is parsed 'into multiple text and entity reference nodes. reader.MoveToContent() reader.MoveToAttribute("misc") while (reader.ReadAttributeValue()) if (reader.NodeType = XmlNodeType.EntityReference) Console.WriteLine("{0} {1}", reader.NodeType, reader.Name) else Console.WriteLine("{0} {1}", reader.NodeType, reader.Value) end if end while finally if Not reader Is Nothing reader.Close() End if end try end sub end class
using System; using System.IO; using System.Xml; public class Sample { public static void Main() { XmlTextReader reader = null; try { //Create the XML fragment to be parsed. string xmlFrag ="<book genre='novel' misc='sale-item &h; 1987'></book>"; //Create the XmlParserContext. XmlParserContext context; string subset = "<!ENTITY h 'hardcover'>"; context = new XmlParserContext(null, null, "book", null, null, subset, "", "", XmlSpace.None); //Create the reader. reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context); //Read the misc attribute. The attribute is parsed //into multiple text and entity reference nodes. reader.MoveToContent(); reader.MoveToAttribute("misc"); while (reader.ReadAttributeValue()){ if (reader.NodeType==XmlNodeType.EntityReference) Console.WriteLine("{0} {1}", reader.NodeType, reader.Name); else Console.WriteLine("{0} {1}", reader.NodeType, reader.Value); } } 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 { // Create the XML fragment to be parsed. String^ xmlFrag = "<book genre='novel' misc='sale-item &h; 1987'></book>"; // Create the XmlParserContext. XmlParserContext^ context; String^ subset = "<!ENTITY h 'hardcover'>"; context = gcnew XmlParserContext( nullptr,nullptr,"book",nullptr,nullptr,subset,"","",XmlSpace::None ); // Create the reader. reader = gcnew XmlTextReader( xmlFrag,XmlNodeType::Element,context ); // Read the misc attribute. The attribute is parsed // into multiple text and entity reference nodes. reader->MoveToContent(); reader->MoveToAttribute( "misc" ); while ( reader->ReadAttributeValue() ) { if ( reader->NodeType == XmlNodeType::EntityReference ) Console::WriteLine( " {0} {1}", reader->NodeType, reader->Name ); else Console::WriteLine( " {0} {1}", reader->NodeType, reader->Value ); } } __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 {
//Create the XML fragment to be parsed.
String xmlFrag = "<book genre='novel' misc='sale-item &h; 1987'>"
+ "</book>";
//Create the XmlParserContext.
XmlParserContext context;
String subset = "<!ENTITY h 'hardcover'>";
context = new XmlParserContext(null, null, "book", null, null,
subset, "", "", XmlSpace.None);
//Create the reader.
reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context);
//Read the misc attribute. The attribute is parsed
//into multiple text and entity reference nodes.
reader.MoveToContent();
reader.MoveToAttribute("misc");
while (reader.ReadAttributeValue()) {
if (reader.get_NodeType().Equals(XmlNodeType.EntityReference)) {
Console.WriteLine("{0} {1}", reader.get_NodeType(), reader.
get_Name());
}
else {
Console.WriteLine("{0} {1}", reader.get_NodeType(),
reader.get_Value());
}
}
}
finally {
if (reader != null) {
reader.Close();
}
}
} //main
} //End class Sample
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