user591410
user591410

Reputation: 3201

Android schema validation with xerces

I am trying to validate an xml file against an xsd schema file using Xerces. I am hitting errors that I am unable to resolve, below is the logcat output. Please note that trying the same code and xercesImpl.jar file in a java application produces accurate validation results but moving the same to android results in errors. Please advice.

E/AndroidRuntime(792): java.lang.NoClassDefFoundError: org.apache.xerces.parsers.SAXParser

Thanks..

Upvotes: 1

Views: 863

Answers (2)

el_mapleee
el_mapleee

Reputation: 91

The solution is to use Apache Xerces ported to Android. There is a project here

You have to do a svn chekout and export the proyect to a jar file to use as a library in your android proyect.

The code to instance SchemaFactory change a little. I show you an example:

import mf.javax.xml.validation.Schema;
import mf.javax.xml.validation.SchemaFactory;
import mf.javax.xml.validation.Validator;
import mf.org.apache.xerces.jaxp.validation.XMLSchemaFactory;

SchemaFactory  factory = new XMLSchemaFactory();
Schema esquema = factory.newSchema(".../file.xsd");

Upvotes: 2

dilix
dilix

Reputation: 3893

The problem is that android doesn't have xerces and validating interface =) But you can simply add validating from xerce:

You can use xerces and native schema validation (in java) in adnroid - you have to download xerces sources and (after some simple manipulations) include it to your own code - you will be able to use DocumentBuilderFactory.setShema method.

https://stackoverflow.com/questions/13142567/xml-schema-validation-xmlsignature-with-xerces-in-android

Upvotes: 0

Related Questions