XPathNavigator.Select 메서드

정의

지정된 XPath 식을 사용하여 노드 집합을 선택합니다.Selects a node set, using the specified XPath expression.

오버로드

Select(String)

지정된 XPath 식을 사용하여 노드 집합을 선택합니다.Selects a node set, using the specified XPath expression.

Select(XPathExpression)

지정된 XPathExpression을 사용하여 노드 집합을 선택합니다.Selects a node set using the specified XPathExpression.

Select(String, IXmlNamespaceResolver)

네임스페이스 접두사를 확인하기 위해 지정된 IXmlNamespaceResolver 개체와 함께 XPath 식을 사용하여 노드 집합을 선택합니다.Selects a node set using the specified XPath expression with the IXmlNamespaceResolver object specified to resolve namespace prefixes.

Select(String)

지정된 XPath 식을 사용하여 노드 집합을 선택합니다.Selects a node set, using the specified XPath expression.

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

매개 변수

xpath
String

XPath 식을 나타내는 String입니다.A String representing an XPath expression.

반환

선택한 노드 집합을 가리키는 XPathNodeIterator입니다.An XPathNodeIterator pointing to the selected node set.

예외

XPath 식에 오류가 포함되어 있거나 해당 반환 형식이 노드 집합이 아닙니다.The XPath expression contains an error or its return type is not a node set.

XPath 식이 잘못되었습니다.The XPath expression is not valid.

예제

다음 예제에서는 Select 노드 집합을 선택 하는 방법입니다.The following example uses the Select method to select a node set.

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

XPathNodeIterator^ nodes = navigator->Select("/bookstore/book");
nodes->MoveNext();
XPathNavigator^ nodesNavigator = nodes->Current;

XPathNodeIterator^ nodesText = nodesNavigator->SelectDescendants(XPathNodeType::Text, false);

while (nodesText->MoveNext())
    Console::WriteLine(nodesText->Current->Value);
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathNodeIterator nodes = navigator.Select("/bookstore/book");
nodes.MoveNext();
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);

while (nodesText.MoveNext())
    Console.WriteLine(nodesText.Current.Value);
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim nodes As XPathNodeIterator = navigator.Select("/bookstore/book")
nodes.MoveNext()
Dim nodesNavigator As XPathNavigator = nodes.Current

Dim nodesText As XPathNodeIterator = nodesNavigator.SelectDescendants(XPathNodeType.Text, False)

While nodesText.MoveNext()
    Console.WriteLine(nodesText.Current.Value)
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 이 메서드가 호출 될 때입니다.The context for the selection is the position of the XPathNavigator when this method is called. 이 메서드를 호출한 후의 XPathNodeIterator 반환 선택 된 노드 집합을 나타냅니다.After calling this method, the XPathNodeIterator returned represents the set of selected nodes. 사용 하 여 MoveNext 메서드는 XPathNodeIterator 선택된 된 노드 집합에 대해 반복 합니다.Use MoveNext method of the XPathNodeIterator to iterate over the selected node set.

다음 C# 코드는 선택한 노드 집합을 반복합니다.The following C# code iterates over the selected set of nodes.

XPathNodeIterator iterator = nav.Select("/bookstore/book");  
while (iterator.MoveNext())  
{  
    Console.WriteLine(Iterator.Current.Name);  
}  

다음은 사용 하는 경우를 고려해 야 할 중요 한 정보는 Select 메서드.The following are important notes to consider when using the Select method.

추가 정보

Select(XPathExpression)

지정된 XPathExpression을 사용하여 노드 집합을 선택합니다.Selects a node set using the specified XPathExpression.

public:
 virtual System::Xml::XPath::XPathNodeIterator ^ Select(System::Xml::XPath::XPathExpression ^ expr);
public virtual System.Xml.XPath.XPathNodeIterator Select (System.Xml.XPath.XPathExpression expr);
abstract member Select : System.Xml.XPath.XPathExpression -> System.Xml.XPath.XPathNodeIterator
override this.Select : System.Xml.XPath.XPathExpression -> System.Xml.XPath.XPathNodeIterator
Public Overridable Function Select (expr As XPathExpression) As XPathNodeIterator

매개 변수

expr
XPathExpression

컴파일된 XPath 쿼리를 포함하는 XPathExpression 개체입니다.An XPathExpression object containing the compiled XPath query.

반환

선택된 노드 집합을 가리키는 XPathNodeIterator입니다.An XPathNodeIterator that points to the selected node set.

예외

XPath 식에 오류가 포함되어 있거나 해당 반환 형식이 노드 집합이 아닙니다.The XPath expression contains an error or its return type is not a node set.

XPath 식이 잘못되었습니다.The XPath expression is not valid.

예제

다음 예제에서는 Select 노드 집합을 선택 하는 방법입니다.The following example uses the Select method to select a node set.

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

XPathExpression^ query = navigator->Compile("/bookstore/book");
XPathNodeIterator^ nodes = navigator->Select(query);
XPathNavigator^ nodesNavigator = nodes->Current;

XPathNodeIterator^ nodesText = nodesNavigator->SelectDescendants(XPathNodeType::Text, false);

while (nodesText->MoveNext())
{
    Console::WriteLine(nodesText->Current->Value);
}
XPathDocument document = new XPathDocument("books.xml");
XPathNavigator navigator = document.CreateNavigator();

XPathExpression query = navigator.Compile("/bookstore/book");
XPathNodeIterator nodes = navigator.Select(query);
XPathNavigator nodesNavigator = nodes.Current;

XPathNodeIterator nodesText = nodesNavigator.SelectDescendants(XPathNodeType.Text, false);

while (nodesText.MoveNext())
{
    Console.WriteLine(nodesText.Current.Value);
}
Dim document As XPathDocument = New XPathDocument("books.xml")
Dim navigator As XPathNavigator = document.CreateNavigator()

Dim query As XPathExpression = navigator.Compile("/bookstore/book")
Dim nodes As XPathNodeIterator = navigator.Select(query)
Dim nodesNavigator As XPathNavigator = nodes.Current

Dim nodesText As XPathNodeIterator = nodesNavigator.SelectDescendants(XPathNodeType.Text, False)

While nodesText.MoveNext()
    Console.WriteLine(nodesText.Current.Value)
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 이 메서드를 호출 하는 경우.The context for the selection is the position of the XPathNavigator when you called this method. 이 메서드를 호출한 후의 XPathNodeIterator 반환 선택 된 노드 집합을 나타냅니다.After you call this method, the XPathNodeIterator returned represents the set of selected nodes. 사용 하 여 MoveNextXPathNodeIterator 선택된 된 노드 집합에 대해 반복 합니다.Use MoveNext on the XPathNodeIterator to iterate over the selected node set.

다음 C# 코드는 선택한 노드 집합을 반복합니다.The following C# code iterates over the selected set of nodes.

XPathNodeIterator ni = nav.Select(expr);  
while (ni.MoveNext())  
{  
    Console.WriteLine(ni.Current.Name);  
}  

다음은 사용 하는 경우를 고려해 야 할 중요 한 정보는 Select 메서드.The following are important notes to consider when using the Select method.

예를 들어, 다음 XML 노드를 포함 하는 문서입니다.For example, suppose the document contains the following XML nodes.

<bookstore xmlns:bk='urn:samples'>  
    <book bk:ISBN='1-325-0980'>  
        <title>Pride And Prejudice</title>  
    </book>  
</bookstore>  

이 경우 다음 C# 코드는 선택 된 bk:ISBN 노드.In this case, the following C# code selects the bk:ISBN node.

XPathExpression expr = nav.Compile("book/@bk:ISBN");  
XmlNamespaceManager mngr = new XmlNamespaceManager(new NameTable());  
mngr.AddNamespace("bk","urn:samples");  
expr.SetContext(mngr);  
XPathNodeIterator ni = nav.Select(expr);  

참고

경우는 XPathExpression 접두사 없는 네임 스페이스 URI가 빈 네임 스페이스는 가정 합니다.If the XPathExpression does not include a prefix, it is assumed that the namespace URI is the empty namespace. XML 기본 네임 스페이스를 포함 하는 경우 반드시 사용 해야는 SetContext 메서드를 제공 하 고는 XmlNamespaceManager 접두사 및 네임 스페이스는 기본 네임 스페이스를 처리 하는 URI 포함 하는 합니다.If your XML includes a default namespace, you must still use the SetContext method and provide an XmlNamespaceManager that contains a prefix and namespace URI to handle the default namespace.

예를 들어, 다음 xml을 사용 합니다.For example, suppose you have the following XML.

<bookstore xmlns="http://www.lucernepublishing.com">  
    <book>  
        <title>Pride And Prejudice</title>  
    </book>  
</bookstore>  

이 경우 다음 C# 코드는 모든 책 노드를 선택합니다.In this case, the following C# code selects all book nodes:

XmlNamespaceManager nsmgr = new XmlNamespaceManager(nav.NameTable);  
nsmgr.AddNamespace("ab", "http://www.lucernepublishing.com");  
XPathExpression expr;  
expr = nav.Compile("//ab:book");  
expr.SetContext(nsmgr);  
XPathNodeIterator ni = nav.Select(expr);  

이 메서드는 상태에 영향을 주지는 XPathNavigator합니다.This method has no effect on the state of the XPathNavigator.

추가 정보

Select(String, IXmlNamespaceResolver)

네임스페이스 접두사를 확인하기 위해 지정된 IXmlNamespaceResolver 개체와 함께 XPath 식을 사용하여 노드 집합을 선택합니다.Selects a node set using the specified XPath expression with the IXmlNamespaceResolver object specified to resolve namespace prefixes.

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

매개 변수

xpath
String

XPath 식을 나타내는 String입니다.A String representing an XPath expression.

resolver
IXmlNamespaceResolver

IXmlNamespaceResolver 개체는 네임스페이스 접두사를 확인하는 데 사용됩니다.The IXmlNamespaceResolver object used to resolve namespace prefixes.

반환

선택된 노드 집합을 가리키는 XPathNodeIterator입니다.An XPathNodeIterator that points to the selected node set.

예외

XPath 식에 오류가 포함되어 있거나 해당 반환 형식이 노드 집합이 아닙니다.The XPath expression contains an error or its return type is not a node set.

XPath 식이 잘못되었습니다.The XPath expression is not valid.

예제

다음 예제를 사용 하 여 설정 노드를 선택 하는 Select 메서드는 XmlNamespaceManager XPath 식의 네임 스페이스 접두사를 확인 하기 위해 지정 하는 개체입니다.The following example illustrates selecting a node set using the Select method with the XmlNamespaceManager object specified to resolve namespace prefixes in the XPath expression.

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

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

XPathNodeIterator^ nodes = navigator->Select("/bk:bookstore/bk:book/bk:price", manager);
// Move to the first node bk:price node.
if(nodes->MoveNext())
{
    // Now nodes.Current points to the first selected node.
XPathNavigator^ nodesNavigator = nodes->Current;

    // Select all the descendants of the current price node.
XPathNodeIterator^ nodesText = nodesNavigator->SelectDescendants(XPathNodeType::Text, false);

    while(nodesText->MoveNext())
    {
Console::WriteLine(nodesText->Current->Value);
    }
}
XPathDocument document = new XPathDocument("contosoBooks.xml");
XPathNavigator navigator = document.CreateNavigator();
XmlNamespaceManager manager = new XmlNamespaceManager(navigator.NameTable);
manager.AddNamespace("bk", "http://www.contoso.com/books");

XPathNodeIterator nodes = navigator.Select("/bk:bookstore/bk:book/bk:price", manager);
// Move to the first node bk:price node
if(nodes.MoveNext())
{
    // now nodes.Current points to the first selected node
    XPathNavigator nodesNavigator = nodes.Current;

    //select all the descendants of the current price node
    XPathNodeIterator nodesText = 
       nodesNavigator.SelectDescendants(XPathNodeType.Text, false);

    while(nodesText.MoveNext())
    {
       Console.WriteLine(nodesText.Current.Value);
    }
}
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 nodes As XPathNodeIterator = navigator.Select("/bk:bookstore/bk:book/bk:price", manager)
' Move to the first node bk:price node.
If (nodes.MoveNext()) Then
    ' Now nodes.Current points to the first selected node.
    Dim nodesNavigator As XPathNavigator = nodes.Current

    ' Select all the descendants of the current price node.
    Dim nodesText As XPathNodeIterator = nodesNavigator.SelectDescendants(XPathNodeType.Text, False)

    While nodesText.MoveNext()
        Console.WriteLine(nodesText.Current.Value)
    End While
End If

이 예제에서는 contosoBooks.xml 파일을 입력으로 사용합니다.The example takes the contosoBooks.xml file as an input.

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

적용 대상