XPathNavigator.SelectSingleNode メソッド

定義

XPathNavigator 内の単一のノードを選択します。

オーバーロード

SelectSingleNode(String, IXmlNamespaceResolver)

名前空間プレフィックスを解決するために指定された XPathNavigator オブジェクトと共に、指定された XPath クエリを使用して IXmlNamespaceResolver オブジェクト内の単一のノードを選択します。

SelectSingleNode(String)

指定された XPath クエリを使用して、XPathNavigator 内の単一のノードを選択します。

SelectSingleNode(XPathExpression)

指定された XPathNavigator オブジェクトを使用して、XPathExpression 内の単一のノードを選択します。

SelectSingleNode(String, IXmlNamespaceResolver)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

名前空間プレフィックスを解決するために指定された XPathNavigator オブジェクトと共に、指定された XPath クエリを使用して IXmlNamespaceResolver オブジェクト内の単一のノードを選択します。

public:
 virtual System::Xml::XPath::XPathNavigator ^ SelectSingleNode(System::String ^ xpath, System::Xml::IXmlNamespaceResolver ^ resolver);
public virtual System.Xml.XPath.XPathNavigator? SelectSingleNode (string xpath, System.Xml.IXmlNamespaceResolver? resolver);
public virtual System.Xml.XPath.XPathNavigator SelectSingleNode (string xpath, System.Xml.IXmlNamespaceResolver resolver);
abstract member SelectSingleNode : string * System.Xml.IXmlNamespaceResolver -> System.Xml.XPath.XPathNavigator
override this.SelectSingleNode : string * System.Xml.IXmlNamespaceResolver -> System.Xml.XPath.XPathNavigator
Public Overridable Function SelectSingleNode (xpath As String, resolver As IXmlNamespaceResolver) As XPathNavigator

パラメーター

xpath
String

XPath 式を表す String

resolver
IXmlNamespaceResolver

XPath クエリの名前空間プレフィックスの解決に使用する IXmlNamespaceResolver オブジェクト。

戻り値

指定された XPath クエリに対して最初に一致するノードが格納された XPathNavigator オブジェクト。クエリ結果がない場合は null

例外

XPath クエリでエラーが発生したか、または XPath 式の戻り値の型がノードではありません。

XPath クエリが無効です。

次の例では、指定した XPath クエリに基づいて オブジェクトから XPathNavigator 1 つのノードを選択し、指定された オブジェクトを XmlNamespaceManager 使用して XPath クエリの名前空間プレフィックスを解決します。

XPathDocument^ document = gcnew XPathDocument("contosoBooks.xml");
XPathNavigator^ navigator = document->CreateNavigator();

XmlNamespaceManager^ manager = gcnew XmlNamespaceManager(navigator->NameTable);
manager->AddNamespace("bk", "http://www.contoso.com/books");

XPathNavigator^ node = navigator->SelectSingleNode("//bk:title", manager);
Console::WriteLine(node->InnerXml);
XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();

XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("bk", "http://www.contoso.com/books");

XPathNavigator node = navigator.SelectSingleNode("//bk:title", manager);
Console.WriteLine(node.InnerXml);
Dim document As XPathDocument = New XPathDocument("contosoBooks.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim manager As XmlNamespaceManager = New XmlNamespaceManager(navigator.NameTable)
manager.AddNamespace("bk", "http://www.contoso.com/books")

Dim node As XPathNavigator = navigator.SelectSingleNode("//bk:title", manager)
Console.WriteLine(node.InnerXml)

この例は、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>  

注釈

メソッドは SelectSingleNode 、指定された XPath クエリに一致する最初のノードを選択します。 メソッドは SelectSingleNode 、 オブジェクトを IXmlNamespaceResolver 使用して名前空間プレフィックスを解決します。

注意

XPath では、すべての名前空間にクエリのプレフィックスを付ける必要があります。 XML ドキュメントで既定の名前空間が使用されている場合でも、オブジェクトに名前空間プレフィックスを IXmlNamespaceResolver 追加する必要があります。

適用対象

SelectSingleNode(String)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

指定された XPath クエリを使用して、XPathNavigator 内の単一のノードを選択します。

public:
 virtual System::Xml::XPath::XPathNavigator ^ SelectSingleNode(System::String ^ xpath);
public virtual System.Xml.XPath.XPathNavigator? SelectSingleNode (string xpath);
public virtual System.Xml.XPath.XPathNavigator SelectSingleNode (string xpath);
abstract member SelectSingleNode : string -> System.Xml.XPath.XPathNavigator
override this.SelectSingleNode : string -> System.Xml.XPath.XPathNavigator
Public Overridable Function SelectSingleNode (xpath As String) As XPathNavigator

パラメーター

xpath
String

XPath 式を表す String

戻り値

指定された XPath クエリに対して最初に一致するノードが格納された XPathNavigator オブジェクト。クエリ結果がない場合は null

例外

XPath クエリでエラーが発生したか、または XPath 式の戻り値の型がノードではありません。

XPath クエリが無効です。

次の例では、指定された XPath クエリに基づいて、 から XPathNavigator 1 つのノードを選択します。

XPathDocument^ document = gcnew XPathDocument("books.xml");
XPathNavigator^ navigator = document->CreateNavigator();

XPathNavigator^ node = navigator->SelectSingleNode("//title");
Console::WriteLine(node->InnerXml);
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathNavigator node = navigator.SelectSingleNode("//title");
Console.WriteLine(node.InnerXml);
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim node As XPathNavigator = navigator.SelectSingleNode("//title")
Console.WriteLine(node.InnerXml)

この例は、books.xml ファイルを入力として使用します。

<?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>  

注釈

メソッドは SelectSingleNode 、オブジェクト内の XPath クエリと一致する最初のノードを XPathNavigator 選択します。

適用対象

SelectSingleNode(XPathExpression)

Source:
XPathNavigator.cs
Source:
XPathNavigator.cs
Source:
XPathNavigator.cs

指定された XPathNavigator オブジェクトを使用して、XPathExpression 内の単一のノードを選択します。

public:
 virtual System::Xml::XPath::XPathNavigator ^ SelectSingleNode(System::Xml::XPath::XPathExpression ^ expression);
public virtual System.Xml.XPath.XPathNavigator? SelectSingleNode (System.Xml.XPath.XPathExpression expression);
public virtual System.Xml.XPath.XPathNavigator SelectSingleNode (System.Xml.XPath.XPathExpression expression);
abstract member SelectSingleNode : System.Xml.XPath.XPathExpression -> System.Xml.XPath.XPathNavigator
override this.SelectSingleNode : System.Xml.XPath.XPathExpression -> System.Xml.XPath.XPathNavigator
Public Overridable Function SelectSingleNode (expression As XPathExpression) As XPathNavigator

パラメーター

expression
XPathExpression

コンパイル済みの XPath クエリが格納されている XPathExpression オブジェクト。

戻り値

指定された XPath クエリに対して最初に一致するノードが格納された XPathNavigator オブジェクト。クエリ結果がない場合は null

例外

XPath クエリでエラーが発生したか、または XPath 式の戻り値の型がノードではありません。

XPath クエリが無効です。

次の例では、 に含まれる XPath クエリに基づいて、 から XPathNavigator 1 つのノードを選択します XPathExpression

XPathDocument^ document = gcnew XPathDocument("books.xml");
XPathNavigator^ navigator = document->CreateNavigator();

XPathExpression^ query = navigator->Compile("//title");

XPathNavigator^ node = navigator->SelectSingleNode(query);
Console::WriteLine(node->InnerXml);
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathExpression query = navigator.Compile("//title");

XPathNavigator node = navigator.SelectSingleNode(query);
Console.WriteLine(node.InnerXml);
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim query As XPathExpression = navigator.Compile("//title")

Dim node As XPathNavigator = navigator.SelectSingleNode(query)
Console.WriteLine(node.InnerXml)

この例は、books.xml ファイルを入力として使用します。

<?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>  

注釈

メソッドはSelectSingleNode、 内の オブジェクトに含まれるコンパイル済みの XPath クエリと一致する最初のノードをXPathExpressionXPathNavigator選択します。

適用対象