My xml file is as under
<Nodes>
<Node>
..
..
<Node>
<Node>
..
..
<Node>
<NodeTemplate>
..
..
<NodeTemplate>
</Nodes>
My main data is in 'Node' elements and the last element is a template. Is there anyway I can ignore the NodeTemplate below?
xdoc = XDocument.Load(ppath);
XElement xmain = xdoc.Element("Nodes");
Sure - ask for just the Node
elements:
var nodes = xdoc.Root.Elements("Nodes");
foreach (var node in nodes)
{
...
}
Or if you want to do lots of work on the doc without NodeTemplate
getting in the way:
xdoc.Root.Elements("NodeTemplate").Remove();
... just remember not to save it over the top of the original, as you'll blow away the NodeTemplate
element...
See more on this question at Stackoverflow