Omitting comments in XML

K

K Viltersten

I noticed that when i use:

foreach (XmlNode tag in tagList[0].ChildNodes) {}

i even collect the comments, so i needed to
remake it as follows.

foreach (XmlNode tag in tagList[0].ChildNodes)
if (tag.Name != "#comment") {}

Is there a recommended way to omit all
comments in the first place? I mean,
something along the lines of:

XmlDocument document = new XmlDocument();
document.Load( XmlReader.Create( path ) );
XmlElement root = document.DocumentElement;
root.SkipTheSupidComments();
 
A

Anthony Jones

K Viltersten said:
I noticed that when i use:

foreach (XmlNode tag in tagList[0].ChildNodes) {}

i even collect the comments, so i needed to
remake it as follows.

foreach (XmlNode tag in tagList[0].ChildNodes)
if (tag.Name != "#comment") {}

Is there a recommended way to omit all
comments in the first place? I mean,
something along the lines of:

XmlDocument document = new XmlDocument();
document.Load( XmlReader.Create( path ) );
XmlElement root = document.DocumentElement;
root.SkipTheSupidComments();

I suspect what you really want is to select only elements in which case:-

root.SelectNodes("*");
 
K

K Viltersten

I noticed that when i use:
foreach (XmlNode tag in tagList[0].ChildNodes) {}

i even collect the comments, so i needed to
remake it as follows.

foreach (XmlNode tag in tagList[0].ChildNodes)
if (tag.Name != "#comment") {}

Is there a recommended way to omit all
comments in the first place? I mean,
something along the lines of:

XmlDocument document = new XmlDocument();
document.Load( XmlReader.Create( path ) );
XmlElement root = document.DocumentElement;
root.SkipTheSupidComments();

I suspect what you really want is to select only elements in which case:

root.SelectNodes("*");

Your suspicion seems very like to be true. :)
Thanks!

Still, i find it very unintutional to regard
the comment as a node.
 
A

Anthony Jones

K Viltersten said:
I noticed that when i use:

foreach (XmlNode tag in tagList[0].ChildNodes) {}

i even collect the comments, so i needed to
remake it as follows.

foreach (XmlNode tag in tagList[0].ChildNodes)
if (tag.Name != "#comment") {}

Is there a recommended way to omit all
comments in the first place? I mean,
something along the lines of:

XmlDocument document = new XmlDocument();
document.Load( XmlReader.Create( path ) );
XmlElement root = document.DocumentElement;
root.SkipTheSupidComments();

I suspect what you really want is to select only elements in which case:

root.SelectNodes("*");

Your suspicion seems very like to be true. :)
Thanks!

Still, i find it very unintutional to regard
the comment as a node.

Everything in XML is a node ;)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top