在Android XML模式验证 [英] XMLSchema validation on Android

查看:136
本文介绍了在Android XML模式验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我保持 JDOM项目,然后我试图证明它在Android上。大多数事情做工精细,但XML Schema验证证明是有问题的......

我的问题是:有没有办法做的XML模式验证在Android?如果有,怎么了?

这样的问题已经被问过,但没有确凿的回答为:

这是我目前知道(纠正我,如果我错了)...:

  • SchemaFactory.newInstance(http://www.w3.org/2001/XMLSchema) - 失败,并抛出:IllegalArgumentException
  • 从Harmony项目的默认ExpatParser在Android不支持XML模式验证。
  • 这是可能加载的Xerces在一个Android应用程序,甚至用它解析,而不是做一个确证解析 - 当您尝试让致命的Andr​​oid异常导致应用程序崩溃

我已经工作了一段时间,现在我已经把下面的研究:

如果任何人有关于XML模式验证Android上的任何详细信息,我将不胜AP preciate任何输入的。

如果有人已经成功地完成XML模式验证XML的,可以帮助我获得工作的JDOM,他们会得到成千上万的互联网点... ;-)和JDOM code将永生和提交信息的功能

解决方案

我着迷的是,经过数年,这仍然是一个悬而未决的问题。 有只似乎是个坏消息,但。按照 AOSP问题跟踪架构验证目前看来不支持与标准Android API和谷歌似乎还不愿意修复它:

  

我们的XML的API(包括SAX,XmlPull和DOM)不支持任何的   以下内容:

  XML模式

 XML的DTD(包括外部实体声明和参考)
 验证

 元素内容空白
 

然而,同样的车票一位评论者引用<一个href="https://$c$c.google.com/p/openkeystore/source/browse/#svn%2Fxsd-4-android%253Fstate%253Dclosed"相对=nofollow>解决方法,并提供了使用Xerces的端口例如code。我不知道这是否超出了你想通了,那么远,但我希望它能帮助。

要包装这件事: 该<一href="https://android.googlesource.com/platform/libcore/+/master/luni/src/main/java/javax/xml/validation/SchemaFactoryFinder.java"相对=nofollow> SchemaFactoryFinder 只知道以下架构定义:

使用任何其他模式定义导致它失败(这将然而,这个记录在调试级别)。显然,这是给你的话,因为你使用的是其他参照2011架构。因此,正确地引用模式定义应该可以解决这个问题。

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:

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':

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.

解决方案

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:

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.

这篇关于在Android XML模式验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆