Extensions.XPathEvaluate 메서드

정의

XPath 식을 평가합니다.

오버로드

Name Description
XPathEvaluate(XNode, String)

XPath 식을 평가합니다.

XPathEvaluate(XNode, String, IXmlNamespaceResolver)

지정된 IXmlNamespaceResolver식을 사용하여 네임스페이스 접두사를 확인하여 XPath 식을 평가합니다.

설명

반환된 컬렉션의 순서는 XML XPath 언어 1.0 권장 사항에 지정되지 않았지만 이 확장 메서드는 문서 순서로 노드를 반환합니다.

노드는 같은 역방향 축 preceding-siblingancestor-or-self을 사용하는 경우에도 문서 순서로 반환됩니다.

XPathEvaluate(XNode, String)

Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs

XPath 식을 평가합니다.

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

매개 변수

node
XNode

XNode XPath 식을 평가할 위치입니다.

expression
String

XPath 식이 포함된 A String 입니다.

반품

, abool, 또는 .를 포함할 수 있는 double개체입니다string.IEnumerable<T>

예제

다음 예제에서는 특성이 있는 작은 XML 트리를 만든 다음 메서드를 XPathEvaluate 사용하여 특성을 검색합니다.

                String xml = "<root a='value'/>";
XDocument d = XDocument.Parse(xml);
IEnumerable att = (IEnumerable)d.XPathEvaluate("/root/@a");
Console.WriteLine(att.Cast<XAttribute>().FirstOrDefault());
                Dim d As XDocument = _
    <?xml version='1.0'?>
    <root a='value'/>
Dim att As IEnumerable = CType(d.XPathEvaluate("/root/@a"), IEnumerable)
Console.WriteLine(att.Cast(Of XAttribute)().FirstOrDefault())

이 예제는 다음과 같은 출력을 생성합니다.

a="value"

설명

컬렉션이 요소 또는 특성의 열거형인 경우 연산자를 Cast 사용하여 컬렉션을 XElement 가져올 수 있습니다 XAttribute.

반환된 컬렉션의 순서는 XML XPath 언어 1.0 권장 사항에 지정되지 않았지만 이 확장 메서드는 문서 순서로 노드를 반환합니다.

노드는 같은 역방향 축 preceding-siblingancestor-or-self을 사용하는 경우에도 문서 순서로 반환됩니다.

적용 대상

XPathEvaluate(XNode, String, IXmlNamespaceResolver)

Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs
Source:
XNodeNavigator.cs

지정된 IXmlNamespaceResolver식을 사용하여 네임스페이스 접두사를 확인하여 XPath 식을 평가합니다.

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

매개 변수

node
XNode

XNode XPath 식을 평가할 위치입니다.

expression
String

XPath 식이 포함된 A String 입니다.

resolver
IXmlNamespaceResolver

XPath 식의 네임스페이스 접두사에 대한 A IXmlNamespaceResolver 입니다.

반품

식을 계산한 결과를 포함하는 개체입니다. 개체는 , abool, a doublestring또는 .IEnumerable<T>

예제

다음 예제에서는 네임스페이스를 포함하는 XML 트리를 만듭니다. XML 문서를 읽는 데 사용됩니다 XmlReader . 그런 다음 XmlNameTable , XmlReader 에서 및 .에서 XmlNamespaceManager가져옵니다XmlNameTable. 요소를 선택할 때 사용합니다 XmlNamespaceManager .

                string markup =
@"<aw:Root xmlns:aw='http://www.adventure-works.com'>
    <aw:Child1 aw:Att='attdata'>child one data 1</aw:Child1>
</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");
IEnumerable atts = (IEnumerable)root.XPathEvaluate("./aw:Child1/@aw:Att", namespaceManager);
IEnumerable<XAttribute> attList = atts.Cast<XAttribute>();
XAttribute att = attList.First();
Console.WriteLine(att);
                Dim markup As XElement = _
    <aw:Root xmlns:aw='http://www.adventure-works.com'>
        <aw:Child1 aw:Att='attdata'>child one data 1</aw:Child1>
    </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 atts As IEnumerable = CType(markup.XPathEvaluate("./aw:Child1/@aw:Att", namespaceManager), IEnumerable)
Dim attList As IEnumerable(Of XAttribute) = atts.Cast(Of XAttribute)()
Dim att As XAttribute = attList.First()
Console.WriteLine(att)

이 예제는 다음과 같은 출력을 생성합니다.

aw:Att="attdata"

설명

이 메서드를 사용하여 네임스페이스 접두사를 포함하는 XPath 식을 평가할 수 있습니다.

반환된 컬렉션의 순서는 XML XPath 언어 1.0 권장 사항에 지정되지 않았지만 이 확장 메서드는 문서 순서로 노드를 반환합니다.

노드는 같은 역방향 축 preceding-siblingancestor-or-self을 사용하는 경우에도 문서 순서로 반환됩니다.

적용 대상