XmlReader.Item[] 属性

定义

在派生类中重写时,获取特性的值。

重载

名称 说明
Item[Int32]

在派生类中重写时,获取具有指定索引的属性的值。

Item[String]

在派生类中重写时,获取具有指定 Name属性的值。

Item[String, String]

在派生类中重写时,获取具有指定 LocalName 属性的值和 NamespaceURI

Item[Int32]

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
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]

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
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]

Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs
Source:
XmlReader.cs

在派生类中重写时,获取具有指定 LocalName 属性的值和 NamespaceURI

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 会引发消息“正在进行异步操作”。

注解

此属性不会移动读取器。

另请参阅

适用于