Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error processing resource while parsing XML with '&' symbol

 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can any one tell me how to write a xml file while the content from the database contains XML-relevant
characters like '&' or '<'..

In the case of normal file writer concept i can write into xml file without any hassle..but while reading the file., Internet Explorer throws an error like Whitespace is not allowed at this location. Error processing resource 'file:///C:xxxxx/xxx.xml Line 202 where line 202 contains a field with " & " .
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Either escape those characters (escape "&" as "&amp;" and "<" as "&lt;") or make the text node be a CDATA section.

I'm not going to go into more details, this should have been in the first chapter of your basic XML resource.
 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell me how to escape those special characters using java code while writing into file or reading from a file.?
 
Paul Clapham
Sheriff
Posts: 21107
32
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I already did. Instead of writing a single "&" you have to write the string "&amp;", and so on. So if your text node looks like "A & B" then you have to write "A &amp; B". That's what "escaping" means.

But you might find it easier to just write each of your text nodes as CDATA sections.
 
Sam Jimzz
Greenhorn
Posts: 28
Eclipse IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Alright Paul Clapham.. I got it.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic