共用方式為


XmlValidatingReader.IsDefault 屬性

定義

取得值,表示目前的節點是否為文件類型定義 (DTD),或結構描述中定義之預設值所產生的屬性。

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

屬性值

Boolean

如果目前節點是 DTD 或結構描述中定義的預設值所產生的屬性,則為 true,如果已經明確設定屬性值,則為 false

範例

下列範例會顯示根項目上的所有屬性節點。

#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

此範例會使用下列檔案做為輸入。

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)>

備註

此屬性只適用于屬性節點。

注意

類別 XmlValidatingReader 在 .NET Framework 2.0 中已過時。 您可以使用 類別和 Create 方法建立驗證 XmlReader 實例 XmlReaderSettings 。 如需詳細資訊,請參閱 XmlReader 參考頁面的<備註>一節。

適用於

另請參閱