Unfortunately, I also faced the requirement to read and accommodate comment data in XML. This is a really nasty practice which should be eliminated by all means. At that time, I managed to fight back and deny such requirements.
But what to do if you, unfortunately, cannot avoid this kind of work?
One of the ways to parse with VBA (why? why?! why not VB.NET?) with ancient MSXML would be using its SAX2. As you can see, this approach can extract comments for you:
Simple API for XML — Wikipedia, the free encyclopedia[
^].
Please start here:
MSXML[
^],
SAX2[
^],
https://msdn.microsoft.com/en-us/library/ms757033%28v=vs.85%29.aspx[
^],
Create a Simple Filter[
^].
The idea is: SAX provides a very efficient forward-only interface to parse the whole thing from the beginning to the end. In the road, you can collect some elements and ignore other; you can figure out current context of each element and other criteria, and decide if you need it, if if you do, add required data to some internal
collection.
In normal practice, comment is one of the element types to be always ignored. Wish you the same. But as you can see, this information can be preserved for you. :-)
I gladly credit Richard Deeming for his comment on my previous solution. I wrote a solution for .NET, but he pointed out my mistake and suggested to look for MSXML, provided appropriate link.
—SA