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!

Parsing an XML document with UTF8 chars

843834Jul 17 2002 — edited Jul 22 2002
Hi,

While trying to parse an XML document containing some greek chars, and therefore saved with UTF8 encoding, I get the following Exception :

org.xml.sax.SAXParseException: The markup in the document preceding the root element must be well-formed.

And the code is as follows :


public static Document loadXmlDocument(String filename)
{
Document doc = null;
try
{
InputSource in = new InputSource(new FileReader(filename));
in.setEncoding("UTF8");
DocumentBuilderFactory dfactory = DocumentBuilderFactory.newInstance();
dfactory.setNamespaceAware(true);
doc = dfactory.newDocumentBuilder().parse(in);
}
catch (Exception e) {
Debug.warnExc(e);
return null;
}
return doc;
}


Any help is welcome !
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 19 2002
Added on Jul 17 2002
7 comments
507 views