1

I'm using IXMLDOMNode::get_childNodes() with preserveWhiteSpace set to true, which causes it to treat carriage returns between elements as nodes. In my child list, I get a few nodes with the name #text.

Is there any way to remove these nodes from my list? I have a CComPtr<IXMLDOMNodeList> object, and there are no members that allow me to add/remove to it.

I'm thinking of using selectNodes() instead, and passing an expression that ignores all nodes with the name #text. Would this be possible?

I just tried selectNodes() and passed the expression //*[not(self::#text)], but that doesn't seem to work.

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
jebusayah
  • 25
  • 1
  • 7
  • [`IXMLDOMNodeList`](https://msdn.microsoft.com/en-us/library/ms757028(v=vs.85).aspx) doesn't look like it wants to be modified as you've found. Depending on what needs to consume that list and/or what further processing you need to do, removing white space (but not other text nodes, right?) on the front-end sounds reasonable. This may be of some help: http://stackoverflow.com/questions/11776910/xpath-expression-to-remove-whitespace – Phil Brubaker Apr 19 '17 at 20:16
  • If you don't want the whitespace nodes, why are you setting `preserveWhiteSpace` to true in the first place? – Remy Lebeau Apr 19 '17 at 22:11
  • The XML files are an outline for a report. It has a grid, with rows/columns. I want to add some whitespace before some of the row names so I can add a header. I can add something like [space%4%] and match it to draw 4 whitespaces whenever it appears, but I would prefer not to if it can be avoided. – jebusayah Apr 20 '17 at 13:52
  • @jebusayah So does that mean there's some formatting "baked in" to the XML data, via strategically-placed spacing? (*Going on that assumption*...) ...while it's going to add work, you might look at [XSLT](https://en.wikipedia.org/wiki/XSLT) for your formatting needs. XML is a vehicle for the data, but isn't traditionally used as its presentation. – Phil Brubaker Apr 21 '17 at 16:42

0 Answers0