| Author |
How to put XML data inside CData
|
Norman Meister
Greenhorn
Joined: Jul 03, 2009
Posts: 17
|
|
Hi All,
I have a string which is infact an xml data. I want to put this xml data inside a cdata and then set it in my main xml tree:
Currently, when i set my xml data into my main xml tree, the xml data gives me encoding problem.
I want this xml data (which inside <ns3:Text>) to be set as part of CDATA so that it appears properly.
I have just previewed my question and somehow the xml snippet appears without any encoding problem here on the forum. The xml data inside <ns3:Text> appears with & lt ..& gt..etc
Could someone please suggest any standard java solution with the help of which i can put my xml data inside CData?
Thanks.
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
Exactly how are you creating this XML document?
If you are building a DOM in memory, why not create a CDATASection node as the child of the ns3:Text Element?
If you are writing text, just add the CDATA start and end tags
Bill
|
Java Resources at www.wbrogden.com
|
 |
Norman Meister
Greenhorn
Joined: Jul 03, 2009
Posts: 17
|
|
i just have a control over preparing the xml string and passing it over to another project which embeds it inside the main xml tree.
I have appended the CData to my xml string but still no change: <ns3:Text><![CDATA[<RawProfile><ROWSET type = "AllLinkedParents"><..../RawProfile>]]></ns3:Text>
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
You say "encoding problem" - what exactly is the error you get?
I got stuck with a similar horrible design in a client's project several years ago - XML formatted tags mixed with HTML inside a CDATA section is a real pain.
It took a lot of fiddling around to get that to come out right.
Eventually I figured out a sequence of encoding the various magic characters.
Bill
|
 |
Norman Meister
Greenhorn
Joined: Jul 03, 2009
Posts: 17
|
|
my xml inside <text> is not appearing properly. It has those < and > signs instea of < >.
Could you please show me one example snipet using Dom with which i can create an Element (w3c.dom), add my xml string within Cdata to it and then set this Element to the main xml tree. There is a interface to the main xml project which can take my newly created Element.
Thanks.
|
 |
Norman Meister
Greenhorn
Joined: Jul 03, 2009
Posts: 17
|
|
my xml inside <text> is not appearing properly. It has those < and > signs instea of < >.
Could you please show me one example snipet using Dom with which i can create an Element (w3c.dom), add my xml string within Cdata to it and then set this Element to the main xml tree. There is a interface to the main xml project which can take my newly created Element.
Thanks.
I have done somethign like this:
But i get the exception on my jboss 5.1 server..org.apache.xerces.jaxp.DocumentBuilderFactoryImpl cannot be cast to javax.xml.parsers.DocumentBuilderFactory
|
 |
William Brogden
Author and all-around good cowpoke
Rancher
Joined: Mar 22, 2000
Posts: 12271
|
|
my xml inside <text> is not appearing properly. It has those < and > signs instea of < >.
"Appearing" is the key to untangling your problem. How are you displaying the results?
As you see, the JavaRanch forum formatter and your browser have modified the appearance of your original text.
Personally, I use a programmer's editor that can show plain text and the hex values of characters when needed to help.
Bill
|
 |
Norman Meister
Greenhorn
Joined: Jul 03, 2009
Posts: 17
|
|
|
I have no idea how to make it appear in a correct way. Have alook at here: Problem
|
 |
 |
|
|
subject: How to put XML data inside CData
|
|
|