Removing comments using XPathNavigator.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);


#region Remove XML comments
XPathNavigator path = xmlDoc.SelectSingleNode("w:document",xmlNSMgr).CreateNavigator();
XPathNodeIterator commentsIterator = path.SelectDescendants(System.Xml.XPath.XPathNodeType.Comment,false);
if (commentsIterator.Count > 0)
while (commentsIterator.MoveNext())


For the following XML:-(We needed to remove "<!–  Generated by Aspose.Words for .NET   –> ")


  <?xml version="1.0" encoding="utf-8" standalone="yes" ?>
– <w:document xmlns:ve="" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:r="" xmlns:m="" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:wp="" xmlns:w10="urn:schemas-microsoft-com:office:word" xmlns:w="" xmlns:wne="">
– <!–  Generated by Aspose.Words for .NET
– <w:body>
– <w:p>
– <w:r>
– <w:rPr>
  <w:b />
  <w:color w:val="FF0000" />
  <w:sz w:val="24" />
  <w:t>Evaluation Only. Created with Aspose.Words. Copyright 2003-2007 Aspose Pty Ltd.</w:t>

  1. Leave a comment

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

Random Thoughts

The World as I see it

Simple Programmer

Making The Complex Simple

Ionic Solutions

Random thoughts on software construction, design patterns and optimization.

Long (Way) Off

A tragic's view from the cricket hinterlands

%d bloggers like this: