Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is starting to use CDATA a breaking change?

Tags:

xml

cdata

xsd

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!

like image 358
kicsit Avatar asked May 21 '10 11:05

kicsit


2 Answers

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.

like image 184
Ned Batchelder Avatar answered Nov 09 '22 13:11

Ned Batchelder


CDATA is a basic part of XML. Failing to support it means the parser is broken (and not a real XML parser (which would be able to cope with elements containing text, CDATA, entities, other elements, comments, etc, etc, etc)).

Since I mentioned it in a comment on another answer, I now have an urge to repeat it here. Not expecting CDATA in XML is like not expecting fish in the sea.

like image 33
Quentin Avatar answered Nov 09 '22 11:11

Quentin