I'm working on a problem where XML exported from our program doesn't escape quotes, (turning "
into "
,) leading to problems on the receiving end. It escapes &s and angle brackets just fine, but not quotes.
When I dug around in the XML export code, I found that it was a pretty straightforward IXmlDomDocument2
DOM interface. But when I got to the step where it produces the XML string output by calling the .XML
method, I ran smack into a wall of proprietariness that I can't trace into, since all the work is taking place inside of C:\Windows\System32\msxml3.dll
.
So apparently Microsoft's IXmlDomDocument2
implementation knows how to escape some symbols but not others. And just to make it worse, the obvious but ugly solution, (running a preprocessing step by recursively traversing the entire document and replacing all quotes in values with '"' before I call .XML
,) won't work because the .XML
method will see those &s in there and escape them! Is there any way to fix this?
This could be considered a bug in the XML Parser used on the other end. The XML Specification details the entities that can be escaped. But they only need to be escaped inside the attributes, which works as shown here:
But the reality is that you may not have control over the other side of the equation. So you can get the desired behavior doing the following: