XmlReader.Item[] 屬性

定義

當在衍生類別中覆寫時,會得到該屬性的值。

多載

名稱 Description
Item[Int32]

當在派生類別中覆寫時,會得到具有指定索引的屬性值。

Item[String]

當在衍生類別中覆寫時,會得到具有指定 Name屬性的值。

Item[String, String]

當在派生類別中覆寫時,會得到具有指定 LocalNameNamespaceURI的屬性值。

Item[Int32]

來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs

當在派生類別中覆寫時,會得到具有指定索引的屬性值。

public:
 virtual property System::String ^ default[int] { System::String ^ get(int i); };
public:
 abstract property System::String ^ default[int] { System::String ^ get(int i); };
public virtual string this[int i] { get; }
public abstract string this[int i] { get; }
member this.Item(int) : string
Default Public Overridable ReadOnly Property Item(i As Integer) As String
Default Public MustOverride ReadOnly Property Item(i As Integer) As String

參數

i
Int32

屬性的索引。

屬性值

指定屬性的值。

例外狀況

在先前非同步操作結束前,會呼叫一個 XmlReader 方法。 此時, InvalidOperationException 會拋出「非同步操作已進行中」的訊息。

範例

以下範例顯示目前節點上的所有屬性。

// Display all attributes.
if (reader.HasAttributes) {
  Console.WriteLine("Attributes of <" + reader.Name + ">");
  for (int i = 0; i < reader.AttributeCount; i++) {
    Console.WriteLine("  {0}", reader[i]);
  }
  // Move the reader back to the element node.
  reader.MoveToElement();
}
' Display all attributes.
If reader.HasAttributes Then
  Console.WriteLine("Attributes of <" + reader.Name + ">")
  Dim i As Integer
  For i = 0 To (reader.AttributeCount - 1)
    Console.WriteLine("  {0}", reader(i))
  Next i
  ' Move the reader back to the element node.
  reader.MoveToElement()
End If

備註

這種特性不會打動讀者。

另請參閱

適用於

Item[String]

來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs

當在衍生類別中覆寫時,會得到具有指定 Name屬性的值。

public:
 virtual property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ name); };
public:
 abstract property System::String ^ default[System::String ^] { System::String ^ get(System::String ^ name); };
public virtual string this[string name] { get; }
public virtual string? this[string name] { get; }
public abstract string this[string name] { get; }
member this.Item(string) : string
Default Public Overridable ReadOnly Property Item(name As String) As String
Default Public MustOverride ReadOnly Property Item(name As String) As String

參數

name
String

屬性的限定名稱。

屬性值

指定屬性的值。 若未找到該屬性,則 null 返回。

例外狀況

在先前非同步操作結束前,會呼叫一個 XmlReader 方法。 此時, InvalidOperationException 會拋出「非同步操作已進行中」的訊息。

範例

以下範例取得 ISBN 屬性的值。

reader.ReadToDescendant("book");
string isbn =reader["ISBN"];
Console.WriteLine("The ISBN value: " + isbn);
reader.ReadToDescendant("book")
Dim isbn As String = reader("ISBN")
Console.WriteLine("The ISBN value: " + isbn)

備註

這種特性不會打動讀者。

若讀取器位於節點 DocumentType 上,此方法可用來取得 PUBLIC 與 SYSTEM 字面,例如, reader["PUBLIC"]

另請參閱

適用於

Item[String, String]

來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs
來源:
XmlReader.cs

當在派生類別中覆寫時,會得到具有指定 LocalNameNamespaceURI的屬性值。

public:
 virtual property System::String ^ default[System::String ^, System::String ^] { System::String ^ get(System::String ^ name, System::String ^ namespaceURI); };
public:
 abstract property System::String ^ default[System::String ^, System::String ^] { System::String ^ get(System::String ^ name, System::String ^ namespaceURI); };
public virtual string this[string name, string namespaceURI] { get; }
public virtual string? this[string name, string? namespaceURI] { get; }
public abstract string this[string name, string namespaceURI] { get; }
member this.Item(string * string) : string
Default Public Overridable ReadOnly Property Item(name As String, namespaceURI As String) As String
Default Public MustOverride ReadOnly Property Item(name As String, namespaceURI As String) As String

參數

name
String

該屬性的當地名稱。

namespaceURI
String

屬性的命名空間 URI。

屬性值

指定屬性的值。 若未找到該屬性,則 null 返回。

例外狀況

在先前非同步操作結束前,會呼叫一個 XmlReader 方法。 此時, InvalidOperationException 會拋出「非同步操作已進行中」的訊息。

備註

這種特性不會打動讀者。

另請參閱

適用於