質問

また一部の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;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top