Edytuj

Udostępnij za pośrednictwem


XmlTextReader.MoveToAttribute Method

Definition

Moves to the specified attribute.

Overloads

MoveToAttribute(Int32)

Moves to the attribute with the specified index.

MoveToAttribute(String)

Moves to the attribute with the specified name.

MoveToAttribute(String, String)

Moves to the attribute with the specified local name and namespace URI.

Remarks

Note

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)

Source:
XmlTextReader.cs
Source:
XmlTextReader.cs
Source:
XmlTextReader.cs

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)

Parameters

i
Int32

The index of the attribute.

Exceptions

The i parameter is less than 0 or greater than or equal to AttributeCount.

Examples

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

Remarks

Note

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.

See also

Applies to

MoveToAttribute(String)

Source:
XmlTextReader.cs
Source:
XmlTextReader.cs
Source:
XmlTextReader.cs

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

Parameters

name
String

The qualified name of the attribute.

Returns

true if the attribute is found; otherwise, false. If false, the reader's position does not change.

Remarks

Note

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.

After calling MoveToAttribute, the Name, NamespaceURI, and Prefix properties reflects the properties of that attribute.

See also

Applies to

MoveToAttribute(String, String)

Source:
XmlTextReader.cs
Source:
XmlTextReader.cs
Source:
XmlTextReader.cs

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

Parameters

localName
String

The local name of the attribute.

namespaceURI
String

The namespace URI of the attribute.

Returns

true if the attribute is found; otherwise, false. If false, the reader's position does not change.

Remarks

Note

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.

After calling MoveToAttribute, the Name, NamespaceURI, and Prefix properties reflects the properties of that attribute.

See also

Applies to