Extensions.Nodes<T>(IEnumerable<T>) 메서드
정의
소스 컬렉션에 있는 모든 문서 및 요소의 자식 노드 컬렉션을 반환합니다.Returns a collection of the child nodes of every document and element in the source collection.
public:
generic <typename T>
where T : System::Xml::Linq::XContainer[System::Runtime::CompilerServices::Extension]
static System::Collections::Generic::IEnumerable<System::Xml::Linq::XNode ^> ^ Nodes(System::Collections::Generic::IEnumerable<T> ^ source);
public static System.Collections.Generic.IEnumerable<System.Xml.Linq.XNode> Nodes<T> (this System.Collections.Generic.IEnumerable<T> source) where T : System.Xml.Linq.XContainer;
static member Nodes : seq<'T (requires 'T :> System.Xml.Linq.XContainer)> -> seq<System.Xml.Linq.XNode> (requires 'T :> System.Xml.Linq.XContainer)
<Extension()>
Public Iterator Function Nodes(Of T As XContainer) (source As IEnumerable(Of T)) As IEnumerable(Of XNode)
형식 매개 변수
- T
XContainer로 제한된 source
의 개체 형식입니다.The type of the objects in source
, constrained to XContainer.
매개 변수
- source
- IEnumerable<T>
소스 컬렉션이 들어 있는 IEnumerable<T>의 XNode입니다.An IEnumerable<T> of XNode that contains the source collection.
반환
소스 컬렉션에 있는 모든 문서 및 요소의 자식 노드에 대한 IEnumerable<T>의 XNode입니다.An IEnumerable<T> of XNode of the child nodes of every document and element in the source collection.
예제
다음 예제에서는 검색의 모든 자식 노드 이름의 요소가 컬렉션의 모든 노드에 대해 Child
합니다.The following example retrieves all of the child nodes for every node in a collection of elements with the name of Child
.
XElement xmlTree = XElement.Parse(
@"<Root><Child>aaa<GrandChild>Text</GrandChild>bbb</Child>" +
@"<Child>ccc<GrandChild>Text</GrandChild>ddd</Child></Root>");
IEnumerable<XNode> nodes = xmlTree.Elements("Child").Nodes();
foreach (XNode node in nodes)
{
switch (node.NodeType)
{
case XmlNodeType.Element:
Console.WriteLine("Element: {0}", ((XElement)node).Name);
break;
case XmlNodeType.Text:
Console.WriteLine("Text: {0}", ((XText)node).Value);
break;
}
}
Dim xmlTree As XElement = _
<Root>
<Child>aaa<GrandChild>Text</GrandChild>bbb</Child>
<Child>ccc<GrandChild>Text</GrandChild>ddd</Child>
</Root>
Dim nodes = xmlTree.<Child>.Nodes()
' Note that XNode uses XmlNodeType, which is in the System.Xml namespace.
For Each node As XNode In nodes
Select Case node.NodeType
Case XmlNodeType.Element
Console.WriteLine("Element: {0}", DirectCast(node, XElement).Name)
Case XmlNodeType.Text
Console.WriteLine("Text: {0}", DirectCast(node, XText).Value)
End Select
Next
이 예제는 다음과 같은 출력을 생성합니다.This example produces the following output:
Text: aaa
Element: GrandChild
Text: bbb
Text: ccc
Element: GrandChild
Text: ddd
설명
이 메서드는 지연된 실행을 사용합니다.This method uses deferred execution.