質問

Say that I have this xml:

<Parent>
    <Child>
        <ChildOfChild>
        </ChildOfChild>
    </Child>
    <Child2>
    </Child2>
</Parent>

I would like to get the name of the nodes?, I know I can get the name of the parent with:

XDocument xd;
String test;
test = xd.Root.Name.LocalName; // test would contain "Parent"

But how do I get the name of the children?

As I can get the next child with xd.Root.FirstNode but I cant find any property or similar to get the name of the child, in this case Child

役に立ちましたか?

解決

xd.Root.FirstNode returns the first child node of the root element, which is not necessary an element (could be a comment for example, which don't have names).

Try the following:

xd.Root.Elements().First().Name.LocalName;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top