XPathNavigator.MoveToFirstAttribute Yöntem
Tanım
Önemli
Bazı bilgiler ürünün ön sürümüyle ilgilidir ve sürüm öncesinde önemli değişiklikler yapılmış olabilir. Burada verilen bilgilerle ilgili olarak Microsoft açık veya zımni hiçbir garanti vermez.
Türetilmiş bir sınıfta geçersiz kılındığında, öğesini XPathNavigator geçerli düğümün ilk özniteliğine taşır.
public:
abstract bool MoveToFirstAttribute();
public abstract bool MoveToFirstAttribute();
abstract member MoveToFirstAttribute : unit -> bool
Public MustOverride Function MoveToFirstAttribute () As Boolean
Döndürülenler
true
XPathNavigator başarılı olursa geçerli düğümün ilk özniteliğine geçer; değilse, false. ise false, öğesinin XPathNavigator konumu değişmez.
Örnekler
Aşağıdaki örnek, dosyadaki MoveToFirstAttribute her kitap books.xml için tüm öznitelikleri görüntülemek için ve MoveToNextAttribute yöntemlerini kullanır.
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
Örnek, books.xml dosyasını giriş olarak alır.
<?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>
Açıklamalar
XPathNavigator şu anda bir öğede konumlandırılmadıysa, bu yöntem döndürür false ve konumu XPathNavigator değişmez.
başarılı bir çağrısından MoveToFirstAttributeLocalNamesonra , NamespaceURI ve Prefix özellikleri özniteliğinin değerlerini yansıtır.
XPathNavigator bir öznitelikte konumlandırıldığında , MoveToPreviousve MoveToFirst yöntemleri MoveToNextgeçerli değildir. Bu yöntemler her zaman döndürür false ve konumunu XPathNavigatordeğiştirmez. Bunun yerine, sonraki öznitelik düğümüne gitmek için öğesini çağırabilirsiniz MoveToNextAttribute .
XPathNavigator özniteliğine konumlandırıldıktan sonra, sahip öğesine gitmek için öğesini çağırabilirsinizMoveToParent.