Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

XMLSchema validation on Android

I maintain the JDOM project and I am trying to 'certify' it on Android. Most things work fine, but XML Schema validation is proving problematic...

My questions are: Is there a way to do XMLSchema validation on Android? If there is, how?

Questions like this have been asked before, but no conclusive answer is given:

  • Android schema validation
  • XML Schema Validation in Android

This is what I currently 'know' (correct me if I am wrong)...:

  • SchemaFactory.newInstance("http://www.w3.org/2001/XMLSchema") - fails with IllegalArgumentException
  • the default 'ExpatParser' in Android from the Harmony project does not support XMLSchema validation.
  • It is possible to load Xerces in an Android app, and even parse with it, but not to do a Validating parse - when you try you get 'FATAL' Android exceptions causing application crashes.

I have been working on this for some time now, and I have put together the following 'research':

  • JDOM2 and Android
  • JDOM2 - Android with Xerces

If anyone has any more information about XMLSchema Validation on Android I would greatly appreciate any input at all.

If anyone has successfully done XMLSchema validation on XML and can help me get the functionality working for JDOM they'll get thousands of internet points ... ;-) and will be immortalized in the JDOM code and commit messages.

like image 820
rolfl Avatar asked Apr 23 '12 03:04

rolfl


People also ask

What is schemas in android?

This object represents a set of constraints that can be checked/ enforced against an XML document. A Schema object is thread safe and applications are encouraged to share it across many parsers in many threads. A Schema object is immutable in the sense that it shouldn't change the set of constraints once it is created.

What is xmlns Android?

XML namespaces are used for providing uniquely named elements and attributes in an XML document. xmlns:android describes the android namespace. Its used like this because this is a design choice by google to handle the errors at compile time.

What is view tag in Android XML?

This class represents the basic building block for user interface components. A View occupies a rectangular area on the screen and is responsible for drawing and event handling. Views are used for Drawing Shapes like Circles,Rectangles,Ovals etc . Just Use View with background and apply a Shape using Custom Drawable.


1 Answers

I'm fascinated that, after several years, this still is an open issue. There only seems to be bad news, though. According to the AOSP Issue Tracker Schema validation currently seems unsupported with the standard Android APIs and Google seems to be unwilling to fix it:

Our XML APIs (including SAX, XmlPull and DOM) don't support any of the following:

 XML Schema 

 XML DTDs (including external entity declarations and references)
 validation

 element content whitespace

However, one commenter of that same ticket references a workaround, and provides example code using a Xerces port. I don't know if this goes beyond what you've figured out, so far, but I hope it helps.

To wrap this up: The SchemaFactoryFinder only knows the following Schema definitions:

  • W3C_XML_SCHEMA10_NS_URI = "http://www.w3.org/XML/XMLSchema/v1.0"
  • W3C_XML_SCHEMA10_NS_URI = "http://www.w3.org/XML/XMLSchema/v1.1"

Using any other schema definition causes it to fail (It will however log this on debug level). Obviously this is the case for you, as you're using another reference to the 2011 schema. So "correctly" referencing the Schema Definition should fix this issue.

like image 131
juwi Avatar answered Oct 25 '22 06:10

juwi