XmlReader.IsDefault Property

When overridden in a derived class, gets a value indicating whether the current node is an attribute that was generated from the default value defined in the DTD or schema.

Namespace:  System.Xml
Assembly:  System.Xml (in System.Xml.dll)

public virtual bool IsDefault { get; }

Property Value

Type: System.Boolean
true if the current node is an attribute whose value was generated from the default value defined in the DTD or schema; false if the attribute value was explicitly set.

IsDefault always returns false for implementations of XmlReader that do not support schema or DTD information. This property applies only to an attribute node.

The following example displays all attributes on the root element.

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

public class Sample 
{
  public static void Main(){

    // Create the reader.
    XmlReader reader = XmlReader.Create("book4.xml");

    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

The example uses the following files as 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)>

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98, Windows CE, Windows Mobile for Smartphone, Windows Mobile for Pocket PC, Xbox 360, Zune

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

.NET Framework

Supported in: 3.5, 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 3.5, 2.0, 1.0

XNA Framework

Supported in: 3.0, 2.0, 1.0
Was this page helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft