XPathNavigator.Select 메서드
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
지정된 XPath 식을 사용하여 노드 집합을 선택합니다.
오버로드
| Name | Description |
|---|---|
| Select(String) |
지정된 XPath 식을 사용하여 노드 집합을 선택합니다. |
| Select(XPathExpression) |
지정된 을 사용하여 노드 집합을 XPathExpression선택합니다. |
| Select(String, IXmlNamespaceResolver) |
네임스페이스 접두사를 확인하기 위해 지정된 개체와 함께 IXmlNamespaceResolver 지정된 XPath 식을 사용하여 노드 집합을 선택합니다. |
Select(String)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
지정된 XPath 식을 사용하여 노드 집합을 선택합니다.
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
매개 변수
반품
XPathNodeIterator 선택한 노드 집합을 가리키는 요소입니다.
예외
XPath 식에 오류가 포함되거나 반환 형식이 노드 집합이 아닙니다.
XPath 식이 잘못되었습니다.
예제
다음 예제에서는 메서드를 Select 사용하여 노드 집합을 선택합니다.
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 .
<?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 위치입니다. 이 메서드를 호출한 후 반환된 XPathNodeIterator 노드 집합을 나타냅니다. 선택한 노드 집합을 MoveNext 반복하려면 메서드를 사용합니다XPathNodeIterator.
다음 C# 코드는 선택한 노드 집합을 반복합니다.
XPathNodeIterator iterator = nav.Select("/bookstore/book");
while (iterator.MoveNext())
{
Console.WriteLine(Iterator.Current.Name);
}
다음은 메서드를 사용할 때 고려해야 할 중요한 참고 사항입니다 Select .
개체의 탐색 메서드를 XPathNavigator 계속 사용하여 개체 내에서 XPathNavigator이동할 수 있습니다. 탐색 메서드는 XPathNavigator .에서 XPathNodeIterator선택한 노드와 독립적입니다.
메서드에 대한 이후 호출은 Select 새 XPathNodeIterator 호출과 일치하는 선택한 노드 집합을 가리키는 새 Select 개체를 반환합니다. 두 XPathNodeIterator 개체는 서로 완전히 독립적입니다.
XPath 식에 네임스페이스 확인이 Select 필요한 경우 인수로 사용하는 오버로드를 XPathExpression 사용합니다.
이 메서드는 .의 XPathNavigator상태에 영향을 주지 않습니다.
추가 정보
- SelectNodes(String)
- SelectSingleNode(String)
- SelectDescendants(XPathNodeType, Boolean)
- SelectChildren(XPathNodeType)
- SelectAncestors(XPathNodeType, Boolean)
적용 대상
Select(XPathExpression)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
지정된 을 사용하여 노드 집합을 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
XPathExpression 컴파일된 XPath 쿼리를 포함하는 개체입니다.
반품
XPathNodeIterator 선택한 노드 집합을 가리키는 항목입니다.
예외
XPath 식에 오류가 포함되거나 반환 형식이 노드 집합이 아닙니다.
XPath 식이 잘못되었습니다.
예제
다음 예제에서는 메서드를 Select 사용하여 노드 집합을 선택합니다.
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 .
<?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 위치입니다. 이 메서드를 호출한 후 반환된 XPathNodeIterator 노드 집합이 표시됩니다. MoveNext 선택한 노드 집합을 반복하는 데 사용합니다XPathNodeIterator.
다음 C# 코드는 선택한 노드 집합을 반복합니다.
XPathNodeIterator ni = nav.Select(expr);
while (ni.MoveNext())
{
Console.WriteLine(ni.Current.Name);
}
다음은 메서드를 사용할 때 고려해야 할 중요한 참고 사항입니다 Select .
개체의 탐색 메서드를 XPathNavigator 계속 사용하여 개체 내에서 XPathNavigator이동할 수 있습니다. 탐색 메서드는 XPathNavigator .에서 XPathNodeIterator선택한 노드와 독립적입니다.
메서드에 대한 이후 호출은 Select 새 XPathNodeIterator 호출과 일치하는 선택한 노드 집합을 가리키는 새 Select 개체를 반환합니다. 두 XPathNodeIterator 개체는 서로 완전히 독립적입니다.
네임스페이스 확인이 XPathExpression 필요한 경우 접두사 및 네임스페이스 URI 쌍을 XmlNamespaceManager추가해야 하며 SetContext 네임스페이스 확인에 사용할 메서드를 지정 XmlNamespaceManager 하기 위해 메서드를 호출해야 합니다.
예를 들어 문서에 다음 XML 노드가 포함되어 있다고 가정합니다.
<bookstore xmlns:bk='urn:samples'>
<book bk:ISBN='1-325-0980'>
<title>Pride And Prejudice</title>
</book>
</bookstore>
이 경우 다음 C# 코드는 노드를 bk:ISBN 선택합니다.
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가 빈 네임스페이스라고 가정합니다. XML에 기본 네임스페이스가 포함되어 있는 경우에도 이 메서드를 SetContext 사용하고 기본 네임스페이스를 처리할 접두사 및 네임스페이스 URI를 포함하는 메서드를 제공해야 XmlNamespaceManager 합니다.
예를 들어 다음 XML이 있다고 가정해 보겠습니다.
<bookstore xmlns="http://www.lucernepublishing.com">
<book>
<title>Pride And Prejudice</title>
</book>
</bookstore>
이 경우 다음 C# 코드는 모든 책 노드를 선택합니다.
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상태에 영향을 주지 않습니다.
추가 정보
- SelectNodes(String)
- SelectSingleNode(String)
- SelectDescendants(XPathNodeType, Boolean)
- SelectChildren(XPathNodeType)
- SelectAncestors(XPathNodeType, Boolean)
적용 대상
Select(String, IXmlNamespaceResolver)
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
- Source:
- XPathNavigator.cs
네임스페이스 접두사를 확인하기 위해 지정된 개체와 함께 IXmlNamespaceResolver 지정된 XPath 식을 사용하여 노드 집합을 선택합니다.
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);
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
매개 변수
- resolver
- IXmlNamespaceResolver
네임스페이 IXmlNamespaceResolver 스 접두사를 확인하는 데 사용되는 개체입니다.
반품
XPathNodeIterator 선택한 노드 집합을 가리키는 항목입니다.
예외
XPath 식에 오류가 포함되거나 반환 형식이 노드 집합이 아닙니다.
XPath 식이 잘못되었습니다.
예제
다음 예제에서는 XPath 식에서 네임스페이 Select 스 접두사를 확인하기 위해 지정된 개체와 함께 XmlNamespaceManager 메서드를 사용하여 노드 집합을 선택하는 방법을 보여 줍니다.
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 .
<?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>