xml parsing - How to validate and parse an UTF-16 encoded XML file in Java? -


i using utf-16 encoded xml file. when tried validate file using schema validation, following exception thrown:

org.xml.sax.saxparseexception: content not allowed in prolog.     @     com.sun.org.apache.xerces.internal.util.errorhandlerwrapper.     createsaxparseexception(unknown source) 

my code given below.

schemafactor schemafactory =    schemafactory.newinstance(xmlconstants.w3c_xml_schema_ns_uri); /** load wxs schema, represented schema instance */ source schemafile = new streamsource(new file("sample.xsd")); try {     schema schema = schemafactory.newschema(schemafile);     javax.xml.validation.validator validator = schema.newvalidator();     validator.validate(new streamsource(new file("testing.xml")));     system.out.println("validation successs"); } catch (saxexception e) {     // todo auto-generated catch block     e.printstacktrace(); } catch (ioexception e) {     // todo auto-generated catch block     e.printstacktrace(); } 

your xml not valid. there content before prolog. xml prolog <?xml version="1.0"?> fix xml. no problem code.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -

debian - 500 Error upon login into Plesk Admin - auth.php3? -