• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

How to put XML data inside CData

 
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Norman Meister
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Ranch Hand
Posts: 52
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have no idea how to make it appear in a correct way. Have alook at here: Problem
 
Get me the mayor's office! I need to tell him about this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic