XmlTextReader.MoveToAttribute 方法
定义
移动到指定的属性。Moves to the specified attribute.
重载
| MoveToAttribute(Int32) |
移动到具有指定索引的属性。Moves to the attribute with the specified index. |
| MoveToAttribute(String) |
移动到具有指定名称的属性。Moves to the attribute with the specified name. |
| MoveToAttribute(String, String) |
移动到具有指定本地名称和命名空间 URI 的属性。Moves to the attribute with the specified local name and namespace URI. |
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlReader 使用方法创建实例 XmlReader.Create 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.
MoveToAttribute(Int32)
移动到具有指定索引的属性。Moves to the attribute with the specified index.
public:
override void MoveToAttribute(int i);
public override void MoveToAttribute (int i);
override this.MoveToAttribute : int -> unit
Public Overrides Sub MoveToAttribute (i As Integer)
参数
- i
- Int32
属性的索引。The index of the attribute.
例外
i 参数小于 0 或大于等于 AttributeCount。The i parameter is less than 0 or greater than or equal to AttributeCount.
示例
下面的示例显示当前节点上的所有属性。The following example displays all attributes on the current node.
public:
void DisplayAttributes( XmlReader^ reader )
{
if ( reader->HasAttributes )
{
Console::WriteLine( "Attributes of <{0}>", reader->Name );
for ( int i = 0; i < reader->AttributeCount; i++ )
{
reader->MoveToAttribute( i );
Console::Write( " {0}={1}", reader->Name, reader->Value );
}
reader->MoveToElement(); //Moves the reader back to the element node.
}
}
public void DisplayAttributes(XmlReader reader)
{
if (reader.HasAttributes)
{
Console.WriteLine("Attributes of <" + reader.Name + ">");
for (int i = 0; i < reader.AttributeCount; i++)
{
reader.MoveToAttribute(i);
Console.Write(" {0}={1}", reader.Name, reader.Value);
}
reader.MoveToElement(); //Moves the reader back to the element node.
}
}
Public Sub DisplayAttributes(reader As XmlReader)
If reader.HasAttributes Then
Console.WriteLine("Attributes of <" & reader.Name & ">")
Dim i As Integer
For i = 0 To reader.AttributeCount - 1
reader.MoveToAttribute(i)
Console.Write(" {0}={1}", reader.Name, reader.Value)
Next i
reader.MoveToElement() 'Moves the reader back to the element node.
End If
End Sub
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlReader 使用方法创建实例 XmlReader.Create 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.
另请参阅
适用于
MoveToAttribute(String)
移动到具有指定名称的属性。Moves to the attribute with the specified name.
public:
override bool MoveToAttribute(System::String ^ name);
public override bool MoveToAttribute (string name);
override this.MoveToAttribute : string -> bool
Public Overrides Function MoveToAttribute (name As String) As Boolean
参数
- name
- String
属性的限定名称。The qualified name of the attribute.
返回
如果找到了属性,则为 true;否则为 false。true if the attribute is found; otherwise, false. 如果为 false,则读取器的位置未改变。If false, the reader's position does not change.
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlReader 使用方法创建实例 XmlReader.Create 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.
调用后, MoveToAttribute Name 、 NamespaceURI 和 Prefix 属性将反映该特性的属性。After calling MoveToAttribute, the Name, NamespaceURI, and Prefix properties reflects the properties of that attribute.
另请参阅
适用于
MoveToAttribute(String, String)
移动到具有指定本地名称和命名空间 URI 的属性。Moves to the attribute with the specified local name and namespace URI.
public:
override bool MoveToAttribute(System::String ^ localName, System::String ^ namespaceURI);
public override bool MoveToAttribute (string localName, string? namespaceURI);
public override bool MoveToAttribute (string localName, string namespaceURI);
override this.MoveToAttribute : string * string -> bool
Public Overrides Function MoveToAttribute (localName As String, namespaceURI As String) As Boolean
参数
- localName
- String
属性的本地名称。The local name of the attribute.
- namespaceURI
- String
属性的命名空间 URI。The namespace URI of the attribute.
返回
如果找到了属性,则为 true;否则为 false。true if the attribute is found; otherwise, false. 如果为 false,则读取器的位置未改变。If false, the reader's position does not change.
注解
备注
从 .NET Framework 2.0 开始,我们建议 XmlReader 使用方法创建实例 XmlReader.Create 以利用新功能。Starting with the .NET Framework 2.0, we recommend that you create XmlReader instances by using the XmlReader.Create method to take advantage of new functionality.
调用后, MoveToAttribute Name 、 NamespaceURI 和 Prefix 属性将反映该特性的属性。After calling MoveToAttribute, the Name, NamespaceURI, and Prefix properties reflects the properties of that attribute.