wood burning stoves 2.0*
The moose likes XML and Related Technologies and the fly likes Error parsing special characters Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Error parsing special characters" Watch "Error parsing special characters" New topic

Error parsing special characters

Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
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.

Bhasker Reddy
Lasse Koskela

Joined: Jan 23, 2002
Posts: 11962
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.

Author of Test Driven (2007) and Effective Unit Testing (2013) [Blog] [HowToAskQuestionsOnJavaRanch]
Bhasker Reddy
Ranch Hand

Joined: Jun 13, 2000
Posts: 176
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.
It is sorta covered in the JavaRanch Style Guide.
subject: Error parsing special characters
Similar Threads
Server Error
startup errors with Websphere Application Server 3.5
Problem in Tomcat start up
XML Parsing Error
Migration issue from Jrun 3.0 to Jrun 4.0