Parsing an XML document with UTF8 chars
843834Jul 17 2002 — edited Jul 22 2002Hi,
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 !