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 引用页的“备注”部分。

适用于

另请参阅