문제
이와 같은 XML이 XDocument 객체에로드 된 경우 :
<Root>
<GroupA>
<Item attrib1="aaa" attrib2="000" />
</GroupA>
<GroupB>
<Item attrib1="bbb" attrib2="111" />
<Item attrib1="ccc" attrib2="222" />
<Item attrib1="ddd" attrib2="333" />
</GroupB>
<GroupC>
<Item attrib1="eee" attrib2="444" />
<Item attrib1="fff" attrib2="555" />
</GroupC>
</Root>
그룹 노드의 이름을 검색하는 쿼리는 어떤 모습입니까?
예를 들어, 쿼리를 반환하고 싶습니다.
GroupA
GroupB
GroupC
해결책
이 같은:
XDocument doc; // populate somehow
// this will give the names as XName
var names = from child in doc.Root.Elements()
select child.Name;
// if you want just the local (no-namespaces) name as a string, use this
var simpleNames = from child in doc.Root.Elements()
select child.Name.LocalName;
제휴하지 않습니다 StackOverflow