XPathNavigator.MoveToFollowing 方法

定義

XPathNavigator按照文件順序移至指定的元素。

多載

名稱 Description
MoveToFollowing(XPathNodeType, XPathNavigator)

將 移動 XPathNavigator 到指定元素的下一個元素 XPathNodeType ,按文件順序移動到指定邊界。

MoveToFollowing(String, String, XPathNavigator)

將 移動 XPathNavigator 到指定本地名稱與命名空間 URI 的元素,並依文件順序移動至指定邊界。

MoveToFollowing(XPathNodeType)

將 移動 XPathNavigator 到文件中指定的下一個元素 XPathNodeType

MoveToFollowing(String, String)

將 移動 XPathNavigator 到以文件順序指定的本地名稱與命名空間 URI 的元素。

MoveToFollowing(XPathNodeType, XPathNavigator)

來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs

將 移動 XPathNavigator 到指定元素的下一個元素 XPathNodeType ,按文件順序移動到指定邊界。

public:
 virtual bool MoveToFollowing(System::Xml::XPath::XPathNodeType type, System::Xml::XPath::XPathNavigator ^ end);
public virtual bool MoveToFollowing(System.Xml.XPath.XPathNodeType type, System.Xml.XPath.XPathNavigator? end);
public virtual bool MoveToFollowing(System.Xml.XPath.XPathNodeType type, System.Xml.XPath.XPathNavigator end);
abstract member MoveToFollowing : System.Xml.XPath.XPathNodeType * System.Xml.XPath.XPathNavigator -> bool
override this.MoveToFollowing : System.Xml.XPath.XPathNodeType * System.Xml.XPath.XPathNavigator -> bool
Public Overridable Function MoveToFollowing (type As XPathNodeType, end As XPathNavigator) As Boolean

參數

type
XPathNodeType

元素的存在 XPathNodeType 。 不 XPathNodeType 可能是 AttributeNamespace

end
XPathNavigator

XPathNavigator位於元素邊界上的物體,該物體XPathNavigator在尋找下一個元素時,電流不會通過。

傳回

true若成功XPathNavigator移動;否則,。 false

範例

在以下範例中,將 XPathNavigator 從檔案根contosoBooks.xml移到price 使用此XPathNavigator方法製作物件Clone的克隆。 克隆 XPathNavigator的 會被放置在 price 元素上的邊界。 克隆 XPathNavigator 者位置的變化不會影響原始 XPathNavigator。 原始檔案XPathNavigator會透過此contosoBooks.xml方法回到檔案根MoveToRoot目錄。 作者的標題以及名字可透過 MoveToFollowing 的方法和 XPathNodeTypeTextan 取得。 MoveToFollowing該方法會回傳為真,直到達到元素price邊界。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing("price", "http://www.contoso.com/books");
XPathNavigator boundary = navigator.Clone();

navigator.MoveToRoot();

while (navigator.MoveToFollowing(XPathNodeType.Text, boundary))
{
    Console.WriteLine(navigator.OuterXml);
}
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing("price", "http://www.contoso.com/books")
Dim boundary As XPathNavigator = navigator.Clone()

navigator.MoveToRoot()

While navigator.MoveToFollowing(XPathNodeType.Text, boundary)
    Console.WriteLine(navigator.OuterXml)
End While

此範例會將 contosoBooks.xml 檔案當作輸入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <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>

備註

適用於

MoveToFollowing(String, String, XPathNavigator)

來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs

將 移動 XPathNavigator 到指定本地名稱與命名空間 URI 的元素,並依文件順序移動至指定邊界。

public:
 virtual bool MoveToFollowing(System::String ^ localName, System::String ^ namespaceURI, System::Xml::XPath::XPathNavigator ^ end);
public virtual bool MoveToFollowing(string localName, string namespaceURI, System.Xml.XPath.XPathNavigator? end);
public virtual bool MoveToFollowing(string localName, string namespaceURI, System.Xml.XPath.XPathNavigator end);
abstract member MoveToFollowing : string * string * System.Xml.XPath.XPathNavigator -> bool
override this.MoveToFollowing : string * string * System.Xml.XPath.XPathNavigator -> bool
Public Overridable Function MoveToFollowing (localName As String, namespaceURI As String, end As XPathNavigator) As Boolean

參數

localName
String

該元素的地方名稱。

namespaceURI
String

元素的命名空間 URI。

end
XPathNavigator

XPathNavigator位於元素邊界上的物體,該物體XPathNavigator在尋找下一個元素時,電流不會通過。

傳回

true若成功XPathNavigator移動;否則,。 false

範例

在以下範例中,將 XPathNavigator 從檔案根contosoBooks.xml移到book 使用此XPathNavigator方法製作物件的克隆Clone,並從元素book移動到下一個first-name元素。 克隆 XPathNavigator的 會被放置在 first-name 元素上的邊界。 克隆 XPathNavigator 者位置的變化不會影響原始 XPathNavigator。 原始XPathNavigator元件接著嘗試使用price以參數傳遞邊界的方法移動到下一個MoveToFollowing元素。 此移動失敗,因為下一個 price 元素超出邊界。 原始 XPathNavigator 元素接著嘗試用相同方法移動到邊界前的下一個 title 元素並成功移動。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing("book", "http://www.contoso.com/books");
XPathNavigator boundary = navigator.Clone();
boundary.MoveToFollowing("first-name", "http://www.contoso.com/books");

navigator.MoveToFollowing("price", "http://www.contoso.com/books", boundary);

Console.WriteLine("Position (after boundary): {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);

navigator.MoveToFollowing("title", "http://www.contoso.com/books", boundary);

Console.WriteLine("Position (before boundary): {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing("book", "http://www.contoso.com/books")
Dim boundary As XPathNavigator = navigator.Clone()
boundary.MoveToFollowing("first-name", "http://www.contoso.com/books")

navigator.MoveToFollowing("price", "http://www.contoso.com/books", boundary)

Console.WriteLine("Position (after boundary): {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

navigator.MoveToFollowing("title", "http://www.contoso.com/books", boundary)

Console.WriteLine("Position (before boundary): {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

此範例會將 contosoBooks.xml 檔案當作輸入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <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 通過的參數邊界未在電流 XPathNavigator 位置之後定位,則忽略該參數。

  • XPathNavigator 邊界參數為 null,則以下以本地名稱與命名空間 URI 指定的元素,位於文件順序中。

  • 這些 MoveToFollowing 方法無法用來移動到屬性或命名空間節點。 如果作為參數傳遞的 XPathNavigator 邊界位於屬性或命名空間節點上,則等 XPathNavigator 同於該邊界參數被放置在其父元素的第一個子節點上。 這確保邊界參數所在的屬性或命名空間節點 XPathNavigator 的父元素能被此方法匹配。

  • MoveToFollowing 方法返回 false,則 XPathNavigator 的位置不變。

適用於

MoveToFollowing(XPathNodeType)

來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs

將 移動 XPathNavigator 到文件中指定的下一個元素 XPathNodeType

public:
 virtual bool MoveToFollowing(System::Xml::XPath::XPathNodeType type);
public virtual bool MoveToFollowing(System.Xml.XPath.XPathNodeType type);
abstract member MoveToFollowing : System.Xml.XPath.XPathNodeType -> bool
override this.MoveToFollowing : System.Xml.XPath.XPathNodeType -> bool
Public Overridable Function MoveToFollowing (type As XPathNodeType) As Boolean

參數

type
XPathNodeType

元素的存在 XPathNodeType 。 不 XPathNodeType 可能是 AttributeNamespace

傳回

true若成功XPathNavigator移動;否則,。 false

範例

在以下範例中,將 XPathNavigator 從檔案根contosoBooks.xml移到bookstore

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing(XPathNodeType.Element);

Console.WriteLine("Position: {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing(XPathNodeType.Element)

Console.WriteLine("Position: {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

此範例會將 contosoBooks.xml 檔案當作輸入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <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>

備註

適用於

MoveToFollowing(String, String)

來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs
來源:
XPathNavigator.cs

將 移動 XPathNavigator 到以文件順序指定的本地名稱與命名空間 URI 的元素。

public:
 virtual bool MoveToFollowing(System::String ^ localName, System::String ^ namespaceURI);
public virtual bool MoveToFollowing(string localName, string namespaceURI);
abstract member MoveToFollowing : string * string -> bool
override this.MoveToFollowing : string * string -> bool
Public Overridable Function MoveToFollowing (localName As String, namespaceURI As String) As Boolean

參數

localName
String

該元素的地方名稱。

namespaceURI
String

元素的命名空間 URI。

傳回

true若成功XPathNavigator移動;否則,。 false

範例

以下範例中,將 XPathNavigator 從檔案根 contosoBooks.xml 移至第一個 price 元素。

XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

navigator.MoveToFollowing("price", "http://www.contoso.com/books");

Console.WriteLine("Position: {0}", navigator.Name);
Console.WriteLine(navigator.OuterXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

navigator.MoveToFollowing("price", "http://www.contoso.com/books")

Console.WriteLine("Position: {0}", navigator.Name)
Console.WriteLine(navigator.OuterXml)

此範例會將 contosoBooks.xml 檔案當作輸入。

<?xml version="1.0" encoding="utf-8" ?>
<bookstore xmlns="http://www.contoso.com/books">
    <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>

備註

MoveToFollowing 方法返回 false,則 XPathNavigator 的位置不變。

適用於