These two LINQ to XML methods seem to be doing the same thing. Would like to know the difference between the two.
var xdoc = XDocument.Load(filename);
xdoc.Root.FirstNode.ElementsAfterSelf();
xdoc.Root.FirstNode.NodesAfterSelf();
Both return methods return
<Title Name="Cooking with Computers: Surreptitious Balance Sheets" Price="11.9500">
<Authors>
<Author Name="O'Leary, O'Leary" />
<Author Name="MacFeather, MacFeather" />
</Authors>
</Title>
<Title Name="You Can Combat Computer Stress!" Price="2.9900">
<Authors>
<Author Name="Green, Green" />
</Authors>
</Title>
Here is the XML
<PubsDatabase>
<Title Name="The Busy Executive's Database Guide" Price="19.9900">
<Authors>
<Author Name="Green, Green" />
<Author Name="Bennet, Bennet" />
</Authors>
</Title>
<Title Name="Cooking with Computers: Surreptitious Balance Sheets" Price="11.9500">
<Authors>
<Author Name="O'Leary, O'Leary" />
<Author Name="MacFeather, MacFeather" />
</Authors>
</Title>
<Title Name="You Can Combat Computer Stress!" Price="2.9900">
<Authors>
<Author Name="Green, Green" />
</Authors>
</Title>
</PubsDatabase>
Nodes will return things like text nodes as well as elements, basically. For example:
This prints
A few things to note:
ElementsAfterSelfwouldn’t.As a side note, attributes don’t count as nodes in LINQ to XML. From the XNode documentation:
This is in contrast to most XML APIs.