XPathNavigator.MoveToFirstAttribute 메서드
정의
파생 클래스에서 재정의되면 XPathNavigator를 현재 노드의 첫 번째 특성으로 이동합니다.When overridden in a derived class, moves the XPathNavigator to the first attribute of the current node.
public:
abstract bool MoveToFirstAttribute();
public abstract bool MoveToFirstAttribute ();
abstract member MoveToFirstAttribute : unit -> bool
Public MustOverride Function MoveToFirstAttribute () As Boolean
반환
XPathNavigator가 현재 노드의 첫 번째 특성으로 이동하면 true
이고, 그러지 않으면 false
입니다.true
if the XPathNavigator is successful moving to the first attribute of the current node; otherwise, false
. false
이면 XPathNavigator의 위치가 변경되지 않습니다.If false
, the position of the XPathNavigator is unchanged.
예제
다음 예제에서는 합니다 MoveToFirstAttribute 및 MoveToNextAttribute 각각에 대 한 모든 특성을 표시 하는 방법 책는 books.xml
파일입니다.The following example uses the MoveToFirstAttribute and MoveToNextAttribute methods to display all the attributes for each book in the books.xml
file.
XPathDocument^ document = gcnew XPathDocument("books.xml");
XPathNavigator^ navigator = document->CreateNavigator();
// Select all book nodes and display all attributes on each book.
XPathNodeIterator^ nodes = navigator->SelectDescendants("book", "", false);
while (nodes->MoveNext())
{
XPathNavigator^ navigator2 = nodes->Current->Clone();
navigator2->MoveToFirstAttribute();
Console::WriteLine("{0} = {1}", navigator2->Name, navigator2->Value);
while (navigator2->MoveToNextAttribute())
{
Console::WriteLine("{0} = {1}", navigator2->Name, navigator2->Value);
}
Console::WriteLine();
}
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();
// Select all book nodes and display all attributes on each book.
XPathNodeIterator nodes = navigator.SelectDescendants("book", "", false);
while (nodes.MoveNext())
{
XPathNavigator navigator2 = nodes.Current.Clone();
navigator2.MoveToFirstAttribute();
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
while (navigator2.MoveToNextAttribute())
{
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value);
}
Console.WriteLine();
}
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()
' Select all book nodes and display all attributes on each book.
Dim nodes As XPathNodeIterator = navigator.SelectDescendants("book", "", False)
While nodes.MoveNext()
Dim navigator2 As XPathNavigator = nodes.Current.Clone()
navigator2.MoveToFirstAttribute()
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value)
While navigator2.MoveToNextAttribute()
Console.WriteLine("{0} = {1}", navigator2.Name, navigator2.Value)
End While
Console.WriteLine()
End While
이 예제에서는 books.xml
파일을 입력으로 사용합니다.The example takes the books.xml
file as an input.
<?xml version="1.0" encoding="utf-8" ?>
<bookstore>
<book genre="autobiography" publicationdate="1981-03-22" ISBN="1-861003-11-0">
<title>The Autobiography of Benjamin Franklin</title>
<author>
<first-name>Benjamin</first-name>
<last-name>Franklin</last-name>
</author>
<price>8.99</price>
</book>
<book genre="novel" publicationdate="1967-11-17" ISBN="0-201-63361-2">
<title>The Confidence Man</title>
<author>
<first-name>Herman</first-name>
<last-name>Melville</last-name>
</author>
<price>11.99</price>
</book>
<book genre="philosophy" publicationdate="1991-02-15" ISBN="1-861001-57-6">
<title>The Gorgias</title>
<author>
<name>Plato</name>
</author>
<price>9.99</price>
</book>
</bookstore>
설명
경우는 XPathNavigator 현재에 배치 되지 않은 요소에이 메서드는 반환 false
의 위치는 XPathNavigator 변경 되지 않습니다.If the XPathNavigator is not currently positioned on an element, this method returns false
and the position of the XPathNavigator does not change.
호출에 성공한 후 MoveToFirstAttribute서 LocalName를 NamespaceURI 및 Prefix 속성 특성의 값을 반영 합니다.After a successful call to MoveToFirstAttribute, the LocalName, NamespaceURI and Prefix properties reflect the values of the attribute. 경우는 XPathNavigator 특성을 메서드에 배치 됩니다 MoveToNext, MoveToPrevious, 및 MoveToFirst 적용 되지 않습니다.When the XPathNavigator is positioned on an attribute, the methods MoveToNext, MoveToPrevious, and MoveToFirst are not applicable. 이러한 메서드는 항상 반환 false
의 위치를 변경 하지 않습니다는 XPathNavigator합니다.These methods always return false
and do not change the position of the XPathNavigator. 대신, 호출할 수 있습니다 MoveToNextAttribute 다음 특성 노드를 이동할 수 있습니다.Rather, you can call MoveToNextAttribute to move to the next attribute node.
후는 XPathNavigator 위치가 특성에 호출할 수 있습니다 MoveToParent , 소유자 요소의 이동할 수 있습니다.After the XPathNavigator is positioned on an attribute, you can call MoveToParent to move to the owner element.