Search code examples
xmlxsdcdata

Is starting to use CDATA a breaking change?


For interaction with a customer's application we use XML documents. That is, we send an XML over HTTP and receive a response XML document the same way. The customer specified two XML schemata that describe the format of both the request and reply. All was working fine, until one day the customer started to use CDATA sections in the response XML. We set up our parser unmindful of CDATA sections, so we failed to interpret them.

My question is: Who made a mistake here? I tried to find an answer in the XML standards, but I'm still not sure. I think I cannot prescribe using or not using CDATA's in an XSD, is that right? If so, is it not enough to agree upon an XSD, but a separate agreement has to be made about CDATA sections? Or one is obliged to be prepared to parse CDATA and regular text as well?

I'm interested in both your personal views and any official statements too. Thank you!


Solution

  • Many XML parsers separate out text and CDATA, which is unfortunate. The mistake was yours: there is no semantic difference between regular text chunks and CDATA, so the sender should be free to choose between them based on the needs of the text at hand.

    The good news is it should be a simple matter to adapt your code.