XmlReader.MoveToNextAttribute 方法

定义

在派生类中重写时,移动到下一个属性。

public:
 abstract bool MoveToNextAttribute();
public abstract bool MoveToNextAttribute();
abstract member MoveToNextAttribute : unit -> bool
Public MustOverride Function MoveToNextAttribute () As Boolean

返回

true 如果存在下一个属性,则为 false 如果没有其他属性。

例外

在上一个异步操作完成之前调用了一个 XmlReader 方法。 在这种情况下, InvalidOperationException 会引发消息“正在进行异步操作”。

示例

以下示例显示当前节点上的所有属性。

if (reader.HasAttributes) {
  Console.WriteLine("Attributes of <" + reader.Name + ">");
  while (reader.MoveToNextAttribute()) {
    Console.WriteLine(" {0}={1}", reader.Name, reader.Value);
  }
  // Move the reader back to the element node.
  reader.MoveToElement();
}
If reader.HasAttributes Then
  Console.WriteLine("Attributes of <" + reader.Name + ">")
  While reader.MoveToNextAttribute()
    Console.WriteLine(" {0}={1}", reader.Name, reader.Value)
  End While
  ' Move the reader back to the element node.
  reader.MoveToElement()
End If

注解

如果当前节点是元素节点,则此方法等效于 MoveToFirstAttribute。 如果 MoveToNextAttribute 返回 true,读取器将移动到下一个属性;否则,读取器的位置不会更改。

适用于