{"id":5985,"date":"2014-04-11T07:06:59","date_gmt":"2014-04-11T07:06:59","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/04\/11\/xml-schema-validation-using-xerces-for-android-collection-of-common-programming-errors\/"},"modified":"2014-04-11T07:06:59","modified_gmt":"2014-04-11T07:06:59","slug":"xml-schema-validation-using-xerces-for-android-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/04\/11\/xml-schema-validation-using-xerces-for-android-collection-of-common-programming-errors\/","title":{"rendered":"XML Schema validation using xerces for Android-Collection of common programming errors"},"content":{"rendered":"<p>I am trying to validate an XML file against an XML Schema file and I have downloaded the https:\/\/code.google.com\/p\/xerces-for-android\/ library to get XML Schema validation to work and I have created the project as a library. I am having trouble getting it to work properly for Android and I get the &#8216;FileNotFoundException&#8217; error and if anyone can see what I am doing wrong or what I need to do to get it to work, then please can you help me.<\/p>\n<p>Here is the code:<\/p>\n<pre><code>public void xmlValidator() throws IOException, SAXException\n{\n    Source schemaFile = new StreamSource(new File(\"device_description_schema.xsd\"));\n    Source xmlFile = new StreamSource(new File(\"device_description.xml\"));\n    SchemaFactory schemaFactory = new XMLSchemaFactory();\n    Schema schema = schemaFactory.newSchema(schemaFile);\n    Validator validator = schema.newValidator();\n    try {\n      validator.validate(xmlFile);\n      System.out.println(xmlFile.getSystemId() + \" is valid\");\n    } catch (SAXException e) {\n      System.out.println(xmlFile.getSystemId() + \" is NOT valid\");\n      System.out.println(\"Reason: \" + e.getLocalizedMessage());\n    }\n}\n<\/code><\/pre>\n<p>And here is the logcat errors:<\/p>\n<pre><code>08-29 15:05:09.461: W\/System.err(14294): java.io.FileNotFoundException: \/device_description_schema.xsd: open failed: ENOENT (No such file or directory)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.util.ErrorHandlerWrapper.createSAXParseException(ErrorHandlerWrapper.java:197)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.util.ErrorHandlerWrapper.error(ErrorHandlerWrapper.java:133)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:395)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.XMLErrorReporter.reportError(XMLErrorReporter.java:305)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.traversers.XSDHandler.reportSchemaError(XSDHandler.java:4098)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument1(XSDHandler.java:2452)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.traversers.XSDHandler.getSchemaDocument(XSDHandler.java:2161)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.traversers.XSDHandler.parseSchema(XSDHandler.java:558)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadSchema(XMLSchemaLoader.java:582)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:549)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.impl.xs.XMLSchemaLoader.loadGrammar(XMLSchemaLoader.java:515)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory.newSchema(XMLSchemaFactory.java:237)\n08-29 15:05:09.461: W\/System.err(14294):    at mf.javax.xml.validation.SchemaFactory.newSchema(SchemaFactory.java:611)\n08-29 15:05:09.461: W\/System.err(14294):    at com.example.mobileapplicationretry.generalclasses.ValidateXml.xmlValidator(ValidateXml.java:49)\n08-29 15:05:09.461: W\/System.err(14294):    at com.example.mobileapplicationretry.MainActivity.onCreate(MainActivity.java:52)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.Activity.performCreate(Activity.java:5133)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2175)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2261)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.ActivityThread.access$600(ActivityThread.java:141)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1256)\n08-29 15:05:09.461: W\/System.err(14294):    at android.os.Handler.dispatchMessage(Handler.java:99)\n08-29 15:05:09.461: W\/System.err(14294):    at android.os.Looper.loop(Looper.java:137)\n08-29 15:05:09.461: W\/System.err(14294):    at android.app.ActivityThread.main(ActivityThread.java:5103)\n08-29 15:05:09.461: W\/System.err(14294):    at java.lang.reflect.Method.invokeNative(Native Method)\n08-29 15:05:09.461: W\/System.err(14294):    at java.lang.reflect.Method.invoke(Method.java:525)\n08-29 15:05:09.461: W\/System.err(14294):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)\n08-29 15:05:09.461: W\/System.err(14294):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)\n08-29 15:05:09.461: W\/System.err(14294):    at dalvik.system.NativeStart.main(Native Method)\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>I am trying to validate an XML file against an XML Schema file and I have downloaded the https:\/\/code.google.com\/p\/xerces-for-android\/ library to get XML Schema validation to work and I have created the project as a library. I am having trouble getting it to work properly for Android and I get the &#8216;FileNotFoundException&#8217; error and if [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-5985","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5985","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=5985"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/5985\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=5985"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=5985"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=5985"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}