This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes Writing & into XML file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Writing & into XML file" Watch "Writing & into XML file" New topic
Author

Writing & into XML file

manoj kumar jena
Greenhorn

Joined: Sep 24, 2007
Posts: 25
Hi Friends,
i am writing data from database into an XML.Then, i am retrieving those data from XML to view on jsp.
but when i am writing the data into XML file i am getting an exception(related to XML format) because my data contains '&' symbol (for example javaranc & rocks).it says "not well-formed".

so how to write these kind of data(which contains special characters like &) into XML?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
Characters that have special meaning in XML have to be "escaped" to pass XML parsers.

You might as well get familiar with the authoritative XML specification at W3C. Look for the section titled:

2.4 Character Data and Markup

Bill
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

And the lazy person's way to escape them is to put every text node into a CDATA section. (That's covered in the XML spec.)
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Writing & into XML file
 
Similar Threads
aborting a process in java
Reload XML, before Parsing
XML parse error
reading an xml file in the web services java file
Saving InputStream to File