2008-09-24 2 views
2

의 이름을 검색하기 : 쿼리 그룹 노드의 이름을 검색하려면 어떻게 보이는지쿼리는 이러한하여 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 

답변

8

뭔가 ... 그게

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; 
+0

의 localName입니다! 고마워 :) – Bullines