Assembly: System.Xml (in system.xml.dll)
Public Property Normalization As Boolean
Dim instance As XmlTextReader Dim value As Boolean value = instance.Normalization instance.Normalization = value
public bool Normalization { get; set; }
public: property bool Normalization { bool get (); void set (bool value); }
/** @property */ public boolean get_Normalization () /** @property */ public void set_Normalization (boolean value)
public function get Normalization () : boolean public function set Normalization (value : boolean)
Valore proprietà
true per normalizzare; in caso contrario false. Il valore predefinito è false.| Tipo di eccezione | Condizione |
|---|---|
| Impostare questa proprietà quando il visualizzatore è chiuso (ReadState è ReadState.Closed). |
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. |
È possibile modificare questa proprietà in qualsiasi momento e rendere effettive le modifiche durante la successiva operazione di lettura.
Nota |
|---|
| Se viene utilizzato XmlTextReader per costruire un oggetto XmlValidatingReader, sarà necessario impostare su true il parametro Normalization per consentire la normalizzazione dei valori di attributo. |
Se il parametro Normalization è impostato su false, verrà disattivato anche il controllo dell'intervallo di caratteri per le entità numeriche. Di conseguenza le entità carattere, quali �, sono consentite.
Di seguito è riportata una descrizione relativa alla normalizzazione del valore degli attributi:
-
Per un riferimento a carattere aggiungere il carattere referenziato al valore dell'attributo.
-
Per un riferimento a entità elaborare in modo ricorsivo il testo di sostituzione dell'entità.
-
Per un carattere di spazio vuoto (#x20, #xD, #xA, #x9) aggiungere #x20 al valore normalizzato. Viene aggiunto un solo carattere #x20 per una sequenza "#xD#xA" compresa in un'entità analizzata esterna oppure per il valore letterale di un'entità analizzata interna.
-
Elaborare gli altri caratteri aggiungendoli al valore normalizzato.
-
Se il valore dichiarato non è CDATA, cancellare eventuali caratteri di spazio iniziali e finali (#x20) e sostituire sequenze di caratteri di spazio (#x20) con un unico carattere di spazio (#x20).
Il XmlTextReader esegue la normalizzazione solo di attributi o CDATA. Non esegue la normalizzazione specifica di DTD, a meno che non ne venga eseguito il wrapping in un XmlValidatingReader.
Per ulteriori informazioni sulla normalizzazione fare riferimento alla Raccomandazione W3C XML 1.0.
Nell'esempio che segue viene illustrato il comportamento del visualizzatore quando la normalizzazione viene attivata e quindi disattivata.
Imports System Imports System.IO Imports System.Xml Imports Microsoft.VisualBasic public class Sample public shared sub Main() ' Create the XML fragment to be parsed. Dim xmlFrag as string = "<item attr1=' test A B C " + Chr(10) & _ " 1 2 3'/>" + Chr(10) & _ "<item attr2=''/>" ' Create the XmlNamespaceManager. Dim nsmgr as XmlNamespaceManager = new XmlNamespaceManager(new NameTable()) ' Create the XmlParserContext. Dim context as XmlParserContext = new XmlParserContext(nothing, nsmgr, nothing, XmlSpace.Preserve) ' Create the reader. Dim reader as XmlTextReader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context) ' Show attribute value normalization. reader.Read() reader.Normalization = false Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1")) reader.Normalization = true Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1")) ' Set Normalization back to false. This allows the reader to accept ' character entities in the � to  range. If Normalization had ' been set to true, character entities in this range throw an exception. reader.Normalization = false reader.Read() reader.MoveToContent() Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr2")) ' Close the reader. reader.Close() end sub end class
using System; using System.IO; using System.Xml; public class Sample{ public static void Main(){ // Create the XML fragment to be parsed. string xmlFrag = @"<item attr1=' test A B C 1 2 3'/> <item attr2=''/>"; // Create the XmlNamespaceManager. XmlNamespaceManager nsmgr = new XmlNamespaceManager(new NameTable()); // Create the XmlParserContext. XmlParserContext context = new XmlParserContext(null, nsmgr, null, XmlSpace.Preserve); // Create the reader. XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element, context); // Show attribute value normalization. reader.Read(); reader.Normalization = false; Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1")); reader.Normalization = true; Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1")); // Set Normalization back to false. This allows the reader to accept // character entities in the � to  range. If Normalization had // been set to true, character entities in this range throw an exception. reader.Normalization = false; reader.Read(); reader.MoveToContent(); Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr2")); // Close the reader. reader.Close(); } }
#using <System.Xml.dll> using namespace System; using namespace System::IO; using namespace System::Xml; int main() { // Create the XML fragment to be parsed. String^ xmlFrag = "<item attr1=' test A B C\n" "1 2 3'/>\n" "<item attr2=''/>\n"; // Create the XmlNamespaceManager. XmlNamespaceManager^ nsmgr = gcnew XmlNamespaceManager( gcnew NameTable ); // Create the XmlParserContext. XmlParserContext^ context = gcnew XmlParserContext( nullptr,nsmgr,nullptr,XmlSpace::Preserve ); // Create the reader. XmlTextReader^ reader = gcnew XmlTextReader( xmlFrag,XmlNodeType::Element,context ); // Show attribute value normalization. reader->Read(); reader->Normalization = false; Console::WriteLine( "Attribute value: {0}", reader->GetAttribute( "attr1" ) ); reader->Normalization = true; Console::WriteLine( "Attribute value: {0}", reader->GetAttribute( "attr1" ) ); // Set Normalization back to false. This allows the reader to accept // character entities in the � to  range. If Normalization had // been set to true, character entities in this range throw an exception. reader->Normalization = false; reader->Read(); reader->MoveToContent(); Console::WriteLine( "Attribute value: {0}", reader->GetAttribute( "attr2" ) ); // Close the reader. reader->Close(); }
import System.*;
import System.IO.*;
import System.Xml.*;
public class Sample
{
public static void main(String[] args)
{
// Create the XML fragment to be parsed.
String xmlFrag = "<item attr1=' test A B C\n" + " 1 2 3'/>\n"
+ " <item attr2=''/>";
// Create the XmlNamespaceManager.
XmlNamespaceManager nsMgr = new XmlNamespaceManager(new NameTable());
// Create the XmlParserContext.
XmlParserContext context = new XmlParserContext(null, nsMgr,
null, XmlSpace.Preserve);
// Create the reader.
XmlTextReader reader = new XmlTextReader(xmlFrag, XmlNodeType.Element,
context);
// Show attribute value normalization.
reader.Read();
reader.set_Normalization(false);
Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"));
reader.set_Normalization(true);
Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr1"));
// Set Normalization back to false. This allows the reader to accept
// character entities in the � to  range. If Normalization had
// been set to true, character entities in this range throw an exception.
reader.set_Normalization(false);
reader.Read();
reader.MoveToContent();
Console.WriteLine("Attribute value:{0}", reader.GetAttribute("attr2"));
// Close the reader.
reader.Close();
} //main
} //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