Not sure if this question belongs in the Java forum or the XML forum.
I'm using JDOM in my Java app. I have an element that contains a CDATA section. Within that CDATA section is another XML document that itself has an element with a CDATA section.
What is the best way to handle the inner CDATA section, so the overall document is processed properly? It looks like the outside CDATA is "stopped" early in the processing by the closing tag of the inner CDATA.
I've tried using > and < characters in place of the greater-than and less-than characters.
I can't separate the XML into two separate documents; the format described above is mandated by another company's software to which I need to match.
However I can't imagine a design that puts an XML document in the middle of a larger text node.
SOAP? The whole concept of envelope & payload is based on this. Ok, that's not the "middle" of a text node, it's the whole node.
Some years ago I ran into something where the envelope (proprietary, not SOAP) had to validate on some schema but the payload could be arbitrary well-formed XML. I think I left tried CDATA but then left the project and made somebody else figure it out.
BTW: I'm totally prepared to be wrong here - far from an XML expert. [ February 22, 2007: Message edited by: Stan James ]
A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
Originally posted by Stan James: SOAP? The whole concept of envelope & payload is based on this. Ok, that's not the "middle" of a text node, it's the whole node.
That's what I meant. Making a node contain an XML document, sure. Making a node contain an XML document surrounded by some other text, that's the idea that boggled me.
Anyway my feeling is that in Java, CDATA is a crutch for people who are avoiding using the standard Java classes to produce XML and are using the ordinary java.io classes. The standard Java classes, at least the ones that serialize data into XML, will do all that ugly escaping that makes an embedded XML document totally unreadable to the human eye while still producing well-formatted XML with the correct meaning.
And my opinion is that if you are doing something as complex as embedding XML documents inside other XML documents, you should really be using a JAXP Transformer to produce your XML. Or a similar serializer from Xerces or JDOM.