Using CDATA in every string content xml element?

Status
Not open for further replies.

Drizzt321

Ars Legatus Legionis
34,921
Subscriptor++
So, something has come up with work on XML generation. So previously we were pretty much just using a Groovy script to string concat hand assemble XML (before my time!), but I'm changing it to using a JAXB @ResponseBody, so turns it nicely into XML, minimal/no whitespace, etc, etc.

Except, my co-worker is worried because we were using CDATA around everything, and so are other folks we query. I've put invalid XML entities into the contents (double quotes, less-than, ampersand, etc) and in the raw XML output I see those as &; entities. So it seems fine. His concern is just he recalls sometime in the last couple of years he made that change because one of the folks querying us said there was a problem because it didn't have a CDATA around it and was breaking their parser.

Personally I think it was because it had XML characters in it which broke it, and he's mis-remembering that even simple, correct text string would break it.

If I were to, https://stackoverflow.com/a/6822815/570291 shows how to easily do it with a simple XmlAdapter, which is what I'd do.
 

Drizzt321

Ars Legatus Legionis
34,921
Subscriptor++
Hm, true. I think it'd be correct to say I'm responsible for ensuring the XML is valid and correct. If it's valid XML, which is it based on the generated xsd and an online validator, then I think it's more up to the other side to use a real XML parser. If it turns out to be a real problem for them, I think I can just add a "cdata everything" API flag and then return it that way.

I was just curious to see if that was kinda a common practice or not, as it also increases the size of the XML. When you're dealing with a few billion queries a day a dozen bytes per element can add up quickly to real bandwidth usage.
 

Drizzt321

Ars Legatus Legionis
34,921
Subscriptor++
I'll just say JAXB marshaller is very efficient. The current XML we do is a groovy View (Spring MVC) which concatenates the XML string in a static fashion, and in the benchmarks I did the JAXB is just as fast or marginally faster. Mostly the issue is the garbage collection that happens periodically, but that's Java for you with lots of object creation/throwing away.
 
Status
Not open for further replies.