I’m trying to integrate a program with a 3rd party service using Delphi XE2. The problem I’m running into is that the service isn’t escaping any of their values in the XML documents they send me.
This is one of their “sample” xml documents
<plans type="array">
<plan>
<id type="integer">1</id>
<series-title>A New Plan</series-title>
<dates>January 16 & 17, 2010</dates>
<plan-title>A New Plan For Your Family</plan-title>
</plan>
...
</plans>
My original plan was just to wrap all the data in CDATA tags, but that doesn’t seem like an ideal solution.
I also thought about searching for the & character and replacing it with & but it doesn’t escape ANY of the user input, including < and > and doing a search and replace for every invalid xml character sounds like a bad idea as well.
Any suggestions on how I should go about dealing with the invalid xml documents?
Start by refusing to refer to these documents as “XML” – they aren’t XML.
Persuade your supplier that many people have adopted XML and are getting benefits from it, and it would be a good idea if they did so too.
If your supplier is under the impression that they are sending you XML, put them right. Being almost XML doesn’t help. It’s like sending you Java code that won’t compile.