Share via


XmlValidatingReader.IsDefault Proprietà

Definizione

Ottiene un valore che indica se il nodo corrente è un attributo generato dal valore predefinito indicato in DTD (Document Type Definition) o nello schema.

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

Valore della proprietà

Boolean

true se il nodo corrente è un attributo il cui valore è stato generato in base al valore predefinito configurato nella definizione DTD o nello schema; false se il valore dell'attributo è stato impostato in modo esplicito.

Esempio

Nell'esempio seguente vengono visualizzati tutti i nodi attributi nell'elemento radice.

#using <System.Xml.dll>

using namespace System;
using namespace System::IO;
using namespace System::Xml;
int main()
{
   
   // Create the reader.
   XmlTextReader^ txtreader = gcnew XmlTextReader( "book4.xml" );
   XmlValidatingReader^ reader = gcnew XmlValidatingReader( txtreader );
   reader->MoveToContent();
   
   // Display each of the attribute nodes, including default attributes.
   while ( reader->MoveToNextAttribute() )
   {
      if ( reader->IsDefault )
            Console::Write( "(default attribute) " );

      Console::WriteLine( " {0} = {1}", reader->Name, reader->Value );
   }

   
   // Close the reader.
   reader->Close();
}

using System;
using System.IO;
using System.Xml;

public class Sample
{
  public static void Main(){

    //Create the reader.
    XmlTextReader txtreader = new XmlTextReader("book4.xml");
    XmlValidatingReader reader = new XmlValidatingReader(txtreader);

    reader.MoveToContent();

    //Display each of the attribute nodes, including default attributes.
    while (reader.MoveToNextAttribute()){
        if (reader.IsDefault)
          Console.Write("(default attribute) ");
        Console.WriteLine("{0} = {1}", reader.Name, reader.Value);
    }

    //Close the reader.
    reader.Close();
  }
} // End class
Imports System.IO
Imports System.Xml

public class Sample 

  public shared sub Main()

    'Create the reader.
    Dim txtreader as XmlTextReader = new XmlTextReader("book4.xml")
    Dim reader as XmlValidatingReader = new XmlValidatingReader(txtreader)

    reader.MoveToContent()

    'Display each of the attribute nodes, including default attributes.
    while (reader.MoveToNextAttribute())
        if (reader.IsDefault)
          Console.Write("(default attribute) ")
        end if
        Console.WriteLine("{0} = {1}", reader.Name, reader.Value)  
    end while           
  
    'Close the reader.
    reader.Close()     
  
  end sub
end class

Nell'esempio vengono usati i file seguenti come input.

book4.xml

<!DOCTYPE book SYSTEM 'book.dtd'>
<book ISBN = '1-861001-57-5'>
  <title>Pride And Prejudice</title>
  <price>19.95</price>
</book>

book.dtd

<!ELEMENT book (title,price)> 
<!ATTLIST book 
   genre CDATA "novel"
   ISBN CDATA #REQUIRED>
<!ELEMENT title (#PCDATA)>
<!ELEMENT price (#PCDATA)>

Commenti

Questa proprietà si applica solo a un nodo attributo.

Nota

La XmlValidatingReader classe è obsoleta in .NET Framework 2.0. È possibile creare un'istanza di XmlReader convalida usando la XmlReaderSettings classe e il Create metodo . Per altre informazioni, vedere la sezione Note della pagina di riferimento XmlReader.

Si applica a

Vedi anche