Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Error parsing special characters

 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to parse a xml file that contains the following string.
Cr�ditos Ajustes & Otros Cargos.
but the parser doesn't recognize this characters. I am using the correct encoding 'iso-8859-1'. It gives me this error

loadDOM threw org.xml.sax.SAXParseException: Illegal character or entity reference syntax.

org.xml.sax.SAXParseException: Illegal character or entity reference syntax.

at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)

at org.apache.crimson.parser.Parser2.fatal(Parser2.java:3170)

at org.apache.crimson.parser.Parser2.maybeReferenceInContent(Parser2.java:2420)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1833)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.content(Parser2.java:1779)

at org.apache.crimson.parser.Parser2.maybeElement(Parser2.java:1507)

at org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:500)

at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)

at org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)

at org.apache.crimson.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:185)

at javax.xml.parsers.DocumentBuilder.parse(DocumentBuilder.java:151)

at com.cingular.olam.tlgpreprocessor.spanish.spanishParser.parse(spanishParser.java:89)java.lang.NullPointerException

at com.cingular.olam.tlgpreprocessor.spanish.spanishParser.parse(spanishParser.java:105)

at com.cingular.olam.tlgpreprocessor.spanish.spanishBill.create(spanishBill.java:33)

at com.cingular.olam.tlgpreprocessor.spanish.spanishBill.create(spanishBill.java:33)

at com.cingular.olam.tlgpreprocessor.spanish.spanishTest.main(spanishTest.java:35)



at com.cingular.olam.tlgpreprocessor.spanish.spanishTest.main(spanishTest.java:35)

Exception in thread "main"
Can you guys help me out here.
 
Lasse Koskela
author
Sheriff
Posts: 11962
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The ampersand in the middle of your string is an illegal character in XML. You need to encode it with "&" or the equivalent numerical character reference.
 
Bhasker Reddy
Ranch Hand
Posts: 176
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not the issue. Actually when I am trying to parse.
Cr�ditos, Ajustes y Otros Cargos.
I can successfully parse and write it out to a file on windows machine.
But on unix, when I parse and print it out to a file, it gets converted to a Cr?ditos, Ajustes y Otros Cargos.
It is generating a question mark on Unix for special characters. Do you guys know the reason why it is happening.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic