But this returns an error saying: Exception in thread "main" */ public class Xml Util download xerces-for-android download silk svn (for windows users) from install silk svn (I did complete install) Once the install is complete, you should have svn in your system path. I went to my desktop then downloaded the xerces project by: svn checkout xerces-for-android-read-only You should then have a new folder on your desktop called xerces-for-android-read-only With the above jar (Eventually I'll make it into a jar, just copied it directly into my source for quick testing.
Illegal Argument Exception: No Schema Factory that implements the schema language specified by: -instance could be loaded Is this a problem with my code or with the actual xsd file? If you wish to do the same, you can making the jar quickly with Ant ( I was able to get the following to work for my xml validation: import
In this example we are going to validate if the package org.kodejava.example.xml; import sax.
Mostly programming in Java, Spring Framework, Hibernate / JPA.
I used the Xerces XMLSchem Factory to do this along with the Java 6 validator.
In order to load the child schema's correctly via an include I had to write a custom resource resolver. Stream Source schema Documents = /* created by your application */; Source instance Document = /* created by your application */; Schema Factory sf = Schema Instance( " Schema s = Schema(schema Documents); Validator v = Validator(); v.validate(instance Document); import org.apache.xerces.parsers.
I found a reference to xerces for android, so I modified my sandbox test of (the following doesn't work with android, the example after this does): import
DDSSettings)unmarshaller.unmarshal(new File(xmlfile Name)); For XML Schema, this method creates a Schema object that performs validation by using location hints specified in documents.XMLSchema Factory xml Schema Factory = new XMLSchema Factory(); Schema schema = xml Schema Schema(new Stream Source ); Validator validator = Validator(); validator.validate(new Stream Source(new String Reader(xml Content))); but this is failing to import all three of the schemas correctly resulting in cannot resolve the name 'blah' to a(n) 'group' component. 2) The string "/home/user/myfile.xml" for the one pointing to your xml file.I've validated this successfully using Python, but having real problems with Java 6.0 and Xerces 2.8.1. Can anybody suggest what's going wrong here, or an easier approach to validate my XML documents?
So just in case anybody else runs into the same issue here, I needed to load a parent schema (and implicit child schemas) from a unit test - as a resource - to validate an XML String.
I have an XML Schema which I have used with xjc to create my JAXB binding. Unfortunately it also doesn't complain when the XML is not well formed.