XmlReader.IsDefault 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
當在衍生類別中覆寫時,會獲得一個值,表示目前節點是從 DTD 或 schema 預設值產生的屬性。
public:
virtual property bool IsDefault { bool get(); };
public:
abstract property bool IsDefault { bool get(); };
public virtual bool IsDefault { get; }
public abstract bool IsDefault { get; }
member this.IsDefault : bool
Public Overridable ReadOnly Property IsDefault As Boolean
Public MustOverride ReadOnly Property IsDefault As Boolean
屬性值
true 如果目前節點是屬性,其值是由 DTD 或 schema 中定義的預設值產生; false 如果屬性值是明確設定的。
例外狀況
在先前非同步操作結束前,會呼叫一個 XmlReader 方法。 此時, InvalidOperationException 會拋出「非同步操作已進行中」的訊息。
範例
以下範例顯示根元素上的所有屬性。
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
範例使用以下檔案作為輸入。
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)>
備註
IsDefault對於不支援結構或 DTD 資訊的實false作,總是回傳XmlReader。 此特性僅適用於屬性節點。