Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does RapidXML support xml:space="preserve"?

I'm reading an XML file where I have "whitespace-only text nodes":

<p>I <b>love</b> <i>Mozart</i>.</p>

In the above (simplified) example, there is whitespace (a single space) between the end tag and the start tag. I need to preserve that space.

When parsing in RapidXML, I am ONLY specifying "parse_comment_nodes", so I assume "parse_trim_whitespace" and "parse_normalize_whitespace" are NOT in effect. So I'm attempting to use the "xml:space" syntax:

<p xml:space="preserve">I <b>love</b> <i>Mozart</i>.</p>

...but it seems as if RapidXML doesn't respect that. As I loop through all the sibling nodes, I never see a node with a value of " ".

I've been reading (and re-reading) the documentation, and searching here on StackOverflow, but so far haven't figured out if this is a syntax issue on my part, or a RapidXML issue.

like image 443
SMGreenfield Avatar asked Oct 11 '25 13:10

SMGreenfield


1 Answers

Now I'm POSITIVE that RapidXML 1.13 doesn't support working around whitespace-only text nodes using the xml:space="preserve" attribute. I located a PATCH for this very issue on SourceForge:

Link to patch for RapidXML 1.13 whitespace-only text node bug

This patch corrects the problem of RapidXML simply never returning/skipping a valid node when it only contained whitespace. It DOES NOT enable use of the xml:space="preserve" attribute. That would be the preferable method of ENABLING the bugfix. Perhaps someone more familiar with the RapidXML project can make that change in the future.

like image 160
SMGreenfield Avatar answered Oct 14 '25 08:10

SMGreenfield



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!