Omitting comments in XML

  • Thread starter Thread starter K Viltersten
  • Start date Start date
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();
 
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("*");
 
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.
 
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 ;)
 
Back
Top