Extensions.XPathSelectElement Extensions.XPathSelectElement Extensions.XPathSelectElement Extensions.XPathSelectElement Method

정의

XPath 식을 사용하여 XElement를 선택합니다.Selects an XElement using a XPath expression.

오버로드

XPathSelectElement(XNode, String) XPathSelectElement(XNode, String) XPathSelectElement(XNode, String) XPathSelectElement(XNode, String)

XPath 식을 사용하여 XElement를 선택합니다.Selects an XElement using a XPath expression.

XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver)

XPath 식을 사용하여 XElement를 선택하고 지정된 IXmlNamespaceResolver를 사용하여 네임스페이스 접두사를 확인합니다.Selects an XElement using a XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

XPathSelectElement(XNode, String) XPathSelectElement(XNode, String) XPathSelectElement(XNode, String) XPathSelectElement(XNode, String)

XPath 식을 사용하여 XElement를 선택합니다.Selects an XElement using a XPath expression.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Xml::Linq::XElement ^ XPathSelectElement(System::Xml::Linq::XNode ^ node, System::String ^ expression);
public static System.Xml.Linq.XElement XPathSelectElement (this System.Xml.Linq.XNode node, string expression);
static member XPathSelectElement : System.Xml.Linq.XNode * string -> System.Xml.Linq.XElement
<Extension()>
Public Function XPathSelectElement (node As XNode, expression As String) As XElement

매개 변수

node
XNode XNode XNode XNode

XPath 식을 평가할 XNode입니다.The XNode on which to evaluate the XPath expression.

expression
String String String String

XPath 식을 포함하는 String입니다.A String that contains an XPath expression.

반환

XElement이거나 null입니다.An XElement, or null.

예제

다음 예제에서는 작은 XML 트리를 만들고 사용 하 여 XPathSelectElement 단일 요소를 선택 합니다.The following example creates a small XML tree and uses XPathSelectElement to select a single element.


                XElement root = new XElement("Root",  
    new XElement("Child1", 1),  
    new XElement("Child2", 2),  
    new XElement("Child3", 3),  
    new XElement("Child4", 4),  
    new XElement("Child5", 5),  
    new XElement("Child6", 6)  
);  
XElement el = root.XPathSelectElement("./Child4");  
Console.WriteLine(el);  

                Dim root As XElement = _  
    <Root>  
        <Child1>1</Child1>  
        <Child2>2</Child2>  
        <Child3>3</Child3>  
        <Child4>4</Child4>  
        <Child5>5</Child5>  
        <Child6>6</Child6>  
    </Root>  
Dim el As XElement = root.XPathSelectElement("./Child4")  
Console.WriteLine(el)  

이 예제는 다음과 같은 출력을 생성합니다.This example produces the following output:

<Child4>4</Child4>  

XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver) XPathSelectElement(XNode, String, IXmlNamespaceResolver)

XPath 식을 사용하여 XElement를 선택하고 지정된 IXmlNamespaceResolver를 사용하여 네임스페이스 접두사를 확인합니다.Selects an XElement using a XPath expression, resolving namespace prefixes using the specified IXmlNamespaceResolver.

public:
[System::Runtime::CompilerServices::Extension]
 static System::Xml::Linq::XElement ^ XPathSelectElement(System::Xml::Linq::XNode ^ node, System::String ^ expression, System::Xml::IXmlNamespaceResolver ^ resolver);
public static System.Xml.Linq.XElement XPathSelectElement (this System.Xml.Linq.XNode node, string expression, System.Xml.IXmlNamespaceResolver resolver);
static member XPathSelectElement : System.Xml.Linq.XNode * string * System.Xml.IXmlNamespaceResolver -> System.Xml.Linq.XElement
<Extension()>
Public Function XPathSelectElement (node As XNode, expression As String, resolver As IXmlNamespaceResolver) As XElement

매개 변수

node
XNode XNode XNode XNode

XPath 식을 평가할 XNode입니다.The XNode on which to evaluate the XPath expression.

expression
String String String String

XPath 식을 포함하는 String입니다.A String that contains an XPath expression.

resolver
IXmlNamespaceResolver IXmlNamespaceResolver IXmlNamespaceResolver IXmlNamespaceResolver

XPath 식의 네임스페이스 접두사에 대한 IXmlNamespaceResolver입니다.An IXmlNamespaceResolver for the namespace prefixes in the XPath expression.

반환

XElement이거나 null입니다.An XElement, or null.

예제

다음 예제에서는 네임 스페이스를 포함 하는 XML 트리를 만듭니다.The following example creates an XML tree that contains a namespace. 여기에서는 XmlReader를 사용하여 XML 문서를 읽습니다.It uses an XmlReader to read the XML document. 그런 다음 XmlNameTable에서 XmlReader을 가져오고 XmlNamespaceManager에서 XmlNameTable를 가져옵니다.It then gets an XmlNameTable from the XmlReader, and an XmlNamespaceManager from the XmlNameTable. 사용 된 XmlNamespaceManager 요소를 선택 하는 경우.It uses the XmlNamespaceManager when selecting an element.


                string markup = @"  
<aw:Root xmlns:aw='http://www.adventure-works.com'>  
    <aw:Child1>child one data</aw:Child1>  
    <aw:Child2>child two data</aw:Child2>  
</aw:Root>";  
XmlReader reader = XmlReader.Create(new StringReader(markup));  
XElement root = XElement.Load(reader);  
XmlNameTable nameTable = reader.NameTable;  
XmlNamespaceManager namespaceManager = new XmlNamespaceManager(nameTable);  
namespaceManager.AddNamespace("aw", "http://www.adventure-works.com");  
XElement child1 = root.XPathSelectElement("./aw:Child1", namespaceManager);  
Console.WriteLine(child1);  

                Dim markup As XElement = _  
    <aw:Root xmlns:aw='http://www.adventure-works.com'>  
        <aw:Child1>child one data</aw:Child1>  
        <aw:Child2>child two data</aw:Child2>  
    </aw:Root>  
Dim reader As XmlReader = markup.CreateReader  
Dim nameTable As XmlNameTable = reader.NameTable  
Dim namespaceManager As XmlNamespaceManager = New XmlNamespaceManager(nameTable)  
namespaceManager.AddNamespace("aw", "http://www.adventure-works.com")  
Dim child1 As XElement = markup.XPathSelectElement("./aw:Child1", namespaceManager)  
Console.WriteLine(child1)  

이 예제는 다음과 같은 출력을 생성합니다.This example produces the following output:

<aw:Child1 xmlns:aw="http://www.adventure-works.com">child one data</aw:Child1>  

설명

네임 스페이스 접두사를 포함 하는 XPath 식을 평가할이 메서드를 사용할 수 있습니다.You can use this method to evaluate XPath expressions that contain namespace prefixes.

적용 대상