XPathNavigator.SelectSingleNode 메서드

정의

XPathNavigator에서 단일 노드를 선택합니다.

오버로드

SelectSingleNode(String, IXmlNamespaceResolver)

네임스페이스 접두사를 확인하기 위해 지정된 IXmlNamespaceResolver 개체와 함께 지정된 XPath 쿼리를 사용하여 XPathNavigator 개체에서 단일 노드를 선택합니다.

SelectSingleNode(String)

지정된 XPath 쿼리를 사용하여 XPathNavigator에서 단일 노드를 선택합니다.

SelectSingleNode(XPathExpression)

지정된 XPathExpression 개체를 사용하여 XPathNavigator에서 단일 노드를 선택합니다.

SelectSingleNode(String, IXmlNamespaceResolver)

네임스페이스 접두사를 확인하기 위해 지정된 IXmlNamespaceResolver 개체와 함께 지정된 XPath 쿼리를 사용하여 XPathNavigator 개체에서 단일 노드를 선택합니다.

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 개체입니다.

반환

XPathNavigator

지정된 XPath 쿼리와 일치하는 첫 번째 노드를 포함하는 XPathNavigator 개체이거나, 쿼리 결과가 없으면 null입니다.

예외

XPath 쿼리에서 오류가 발생했거나 XPath 식의 반환 형식이 노드가 아닙니다.

XPath 쿼리가 잘못되었습니다.

예제

다음 예제에서는 지정된 XPath 쿼리에 따라 개체에서 XPathNavigator 단일 노드를 선택하고 지정된 개체를 사용하여 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)

지정된 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입니다.

반환

XPathNavigator

지정된 XPath 쿼리와 일치하는 첫 번째 노드를 포함하는 XPathNavigator 개체이거나, 쿼리 결과가 없으면 null입니다.

예외

XPath 쿼리에서 오류가 발생했거나 XPath 식의 반환 형식이 노드가 아닙니다.

XPath 쿼리가 잘못되었습니다.

예제

다음 예제에서는 지정된 XPath 쿼리에 XPathNavigator 따라 단일 노드를 선택합니다.

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)

지정된 XPathExpression 개체를 사용하여 XPathNavigator에서 단일 노드를 선택합니다.

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 개체입니다.

반환

XPathNavigator

지정된 XPath 쿼리와 일치하는 첫 번째 노드를 포함하는 XPathNavigator 개체이거나, 쿼리 결과가 없으면 null입니다.

예외

XPath 쿼리에서 오류가 발생했거나 XPath 식의 반환 형식이 노드가 아닙니다.

XPath 쿼리가 잘못되었습니다.

예제

다음 예제에서는 에 포함된 XPath 쿼리에 따라 단일 노드 XPathNavigatorXPathExpression선택합니다.

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 쿼리와 일치하는 첫 번째 노드를 XPathExpression XPathNavigator선택합니다.

적용 대상