This week's book giveaway is in the OCMJEA forum.
We're giving away four copies of OCM Java EE 6 Enterprise Architect Exam Guide and have Paul Allen & Joseph Bambara on-line!
See this thread for details.
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Error parsing special characters" Watch "Error parsing special characters" New topic
Author

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
author
Sheriff

Joined: Jan 23, 2002
Posts: 11962
    
    5
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Error parsing special characters