Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Character reference "&#16" is an invalid XML character

843834Jun 27 2004 — edited Jun 29 2004
Hi everyone;

I had writen a SAXparser which was working fine until it hit a chinese character. I did not do any encoding earlier but this time I specified the encoding using several Methodologies but nothing worked. the sample of the XML i am trying to parse is

<DATA>
<ROW>
four#202;&#22;star
</ROW>
</DATA>

This data has been entered by a chinese client. The data is properly stored in database. Also when my delphi applications forms and returns the XML there is no error. When i display this on the browser how ever since I do not have chinese charecter set IE display's as a box. so no errors on that part. I pass this XML back to servlet to generate a report based on the XML data. That is the time when i hit errors.

the sample code for parsing the XML is as stated below


import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import java.util.*;
import java.io.*;
import java.net.URLEncoder;
import java.net.URLDecoder;
public class MySaxParser extends DefaultHandler{

...........................................
......................................
........................................
public void printString(String XMLString){


System.setProperty("javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");

String uri=XMLString;

try {
SAXParserFactory parserFactory = SAXParserFactory.newInstance();
parserFactory.setValidating(false);
parserFactory.setNamespaceAware(false);
MySaxParser MySaxParserInstance = new MySaxParser();
SAXParser parser = parserFactory.newSAXParser();
XMLReader reader = parser.getXMLReader();
//this is what i tried the latest
String nowuri=URLEncoder.encode(uri,"UTF-16");
String lasturi=URLDecoder.decode(uri,"UTF-16");

InputSource is = new InputSource(new StringReader(lasturi));

// I have tried to set the encoding at all the levels ... also u might have noticed that my XML does not
//have any encoding style mentioned.
is.setEncoding("UTF-16");
reader.parse(is);


}
catch(IOException ex) {
ex.printStackTrace();
}
catch(SAXException ex) {
ex.printStackTrace();
}
catch(ParserConfigurationException ex) {
ex.printStackTrace();
}
catch(FactoryConfigurationError ex) {
ex.printStackTrace();
}



Thanks in advance.

Regards

Jesh
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 27 2004
Added on Jun 27 2004
4 comments
960 views