与公地沼气池java.lang.UnsupportedOperationException安卓:这分析器不支持规范和QUOT;未知QUOT&;版本" 0.0" [英] android with commons-digester java.lang.UnsupportedOperationException: This parser does not support specification "Unknown" version "0.0"

查看:354
本文介绍了与公地沼气池java.lang.UnsupportedOperationException安卓:这分析器不支持规范和QUOT;未知QUOT&;版本" 0.0"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要使用commons-digester.jar在android的处理XML文件
实际上,这是一个使用公地digester.jar用于XML处理Java中开源程序
我需要改变它支持Android
但这种错误发生:

Digester.getParser:
java.lang.UnsupportedOperationException:该分析器不支持规范未知版本0.0

显示java.lang.NullPointerException
11月3日至29日:24:02.590:
W / System.err的(17018):在org.apache.commons.digester3.Digester.getXMLReader(Digester.java:790)
11月3日至29日:24:02.590:W / System.err的(17018):在org.apache.commons.digester3.Digester.parse(Digester.java:1588)
11月3日至29日:24:02.590:W / System.err的(17018):在org.apache.commons.digester3.Digester.parse(Digester.java:1557)
11月3日至29日:24:02.590:W / System.err的(17018):在com.tashkeel.android.utilities.alkhalil.DbLoader.Load prefixes(DbLoader.java:65)
11月3日至29日:24:02.590:W / System.err的(17018):在com.tashkeel.android.utilities.alkhalil.analyse.Analyzer(Analyzer.java:64)。
11月3日至29日:24:02.600:W / System.err的(17018):在com.tashkeel.android.MainActivity $ 1.run(MainActivity.java:80)
11月3日至29日:24:02.600:W / System.err的(17018):在java.lang.Thread.run(Thread.java:856)
11月3日至29日:24:03.240:W / System.err的(17018):

和使用公地沼气池code样品

 沼气池沼气池=新建沼气池();
 digester.addObjectCreate(prefixes,Lists.class);
 digester.addObjectCreate(prefixes / prefixe,prefixe.class);
  digester.addSetProperties(prefixes / prefixe,unvoweledform
           unvoweledform);
 digester.addSetProperties(prefixes / prefixe,voweledform  voweledform);
  digester.addSetProperties(prefixes / prefixe,说明,说明); digester.addSetProperties(prefixes / prefixe,CLASSE,CLASSE); digester.addSetNext(prefixes / prefixe,增加prefixe); 回报(列表)digester.parse(preF);

XML的一部分,我尝试解析:

 <?XML版本=1.0编码=UTF-8&GT?;
< prefixes>
    < prefixe unvoweledform =voweledform =DESC =CLASSE =C1>
    < / prefixe>
    < prefixe unvoweledform =وvoweledform =وDESC =حرفالعطفCLASSE =C1>
        < / prefixe>
    < prefixe unvoweledform =فvoweledform =فDESC =حرفالعطفأوالاستئناف
CLASSE =C1>
     < / prefixe>
    < / prefixes>


解决方案

查看源$ C ​​$ C的沼气池,是什么把它归结为似乎是这个code:

 的SAXParserFactory厂= SAXParserFactory.newInstance();
factory.setNamespaceAware(namespaceAware);
factory.setXIncludeAware(xincludeAware);
factory.setValidating(验证);
factory.setSchema(模式);

然后检查<一的JavaDoc href=\"https://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/SAXParserFactory.html#setSchema(javax.xml.validation.Schema)\"相对=nofollow>的SAXParserFactory#的setSchema :


  

一个解析器必须能够与任何模式的实施工作...
  抛出:UnsupportedOperationException - 当实现没有
  覆盖此方法。


所以我的猜测是你的code正在接收不支持架构以某种方式的SAXParserFactory 实施

有在<故障排除的一些技巧href=\"https://docs.oracle.com/javase/7/docs/api/javax/xml/parsers/SAXParserFactory.html#newInstance%28%29\"相对=nofollow> SAXParserFactory.html#的newInstance DOCO,但你也可以随便找正与返回的确切解析器类以下(无需蒸煮code):

 的SAXParserFactory厂= SAXParserFactory.newInstance();
通信System.err.println(SAXParserFactory类是+ factory.getClass()的getName());

另外,从<一href=\"http://developer.android.com/reference/javax/xml/parsers/SAXParserFactory.html#setSchema%28javax.xml.validation.Schema%29\"相对=nofollow> Android版的SAXParserFactory DOCO :


  

UnsupportedOperationException异常为了向后兼容时,
  早期版本的JAXP的实现时,这个例外
  将被抛出。


所以,你可能要检查你使用的是JAXP等版本。

更新

既然你不需要模式,你可以试试这个可以工作,而不是让沼气池创造... ...的的SAXParserFactory 给你,你自己创建一个 - 那这样就可以避免在调用的setSchema 这看起来可能是这个问题:

  //创建自己的SAXParserFactory,但不调用任何set方法,除非你明确地需要
最终的SAXParserFactory myfactory = SAXParserFactory.newInstance();//myfactory.setNamespaceAware(namespaceAware);
//myfactory.setXIncludeAware(xincludeAware);
//myfactory.setValidating(验证);
//myfactory.setSchema(模式);//创建自己的沼气池,并重写getFactory方法来回报您自己的工厂
沼气池沼气池=新建沼气池(){
  @覆盖
  公众的SAXParserFactory getFactory(){
    返回myfactory;
  }
};//使用这个沼气池正常您code休息...

没有做任何Android开发此刻所以不能对此进行测试,但看起来像它可以工作...

更新2

所以这看起来像是固定的模式问题,你现在有什么似乎是一个单独的类加载器的问题。这实际上是一个单独的问题,但这里有一个可能的黑客攻击......绕过banutils自省,只是自己处理的属性与自定义规则。因为你必须在你的例子相当简单的XML这是唯一真正实用的 - 什么更复杂,这一点,这种方法行不通变成:

 最终名单,LT; prefixe&GT;名单=新的ArrayList&LT;&GT;();
最终的SAXParserFactory厂= SAXParserFactory.newInstance();沼气池沼气池=新建沼气池(){
  @覆盖
  公众的SAXParserFactory getFactory(){
     的System.out.println(使用自定义工厂......);
    回厂;
  }
};digester.addRule(prefixes / prefixe,新规则(){
  @覆盖
  公共无效开始(字符串命名,字符串名称,属性的属性)抛出异常{
    prefixe prefixe =新的prefixe();
    prefixe.setUnvoweledform(attributes.getValue(unvoweledform));
    prefixe.setVoweledform(attributes.getValue(voweledform));
    prefixe.setDesc(attributes.getValue(DESC));
    prefixe.setClasse(attributes.getValue(CLASSE));
    list.add(prefixe);
  }
});digester.parse(...);

请注意,它看起来像你有类加载器问题的地方(除非你有BeanUtils的版本已经以某种方式?被削弱)和我强烈建议你尝试去那些底部,因为它们可能会回来一次又一次地咬你......

祝你好运!

I have to use commons-digester.jar for processing xml files in android actually this was open source program that uses commons-digester.jar for xml processing in Java and I need to change it to support Android but this error happens :

Digester.getParser: java.lang.UnsupportedOperationException: This parser does not support specification "Unknown" version "0.0"

java.lang.NullPointerException 03-29 11:24:02.590: W/System.err(17018): at org.apache.commons.digester3.Digester.getXMLReader(Digester.java:790) 03-29 11:24:02.590: W/System.err(17018): at org.apache.commons.digester3.Digester.parse(Digester.java:1588) 03-29 11:24:02.590: W/System.err(17018): at org.apache.commons.digester3.Digester.parse(Digester.java:1557) 03-29 11:24:02.590: W/System.err(17018): at com.tashkeel.android.utilities.alkhalil.DbLoader.LoadPrefixes(DbLoader.java:65) 03-29 11:24:02.590: W/System.err(17018): at com.tashkeel.android.utilities.alkhalil.analyse.Analyzer.(Analyzer.java:64) 03-29 11:24:02.600: W/System.err(17018): at com.tashkeel.android.MainActivity$1.run(MainActivity.java:80) 03-29 11:24:02.600: W/System.err(17018): at java.lang.Thread.run(Thread.java:856) 03-29 11:24:03.240: W/System.err(17018):

and sample of code that uses commons-digester

 Digester digester = new Digester();
 digester.addObjectCreate("prefixes", Lists.class);
 digester.addObjectCreate("prefixes/prefixe", Prefixe.class);
  digester.addSetProperties("prefixes/prefixe", "unvoweledform",     
           "unvoweledform");
 digester.addSetProperties("prefixes/prefixe", "voweledform",

  "voweledform");
  digester.addSetProperties("prefixes/prefixe", "desc", "desc");

 digester.addSetProperties("prefixes/prefixe", "classe", "classe");

 digester.addSetNext("prefixes/prefixe", "addPrefixe");

 return (Lists)digester.parse(pref);

part of xml that I try to parse :

  <?xml version="1.0" encoding="utf-8" ?>
<prefixes>
    <prefixe unvoweledform="" voweledform="" desc="" classe="C1">
    </prefixe>
    <prefixe unvoweledform="و" voweledform="وَ" desc="حرف العطف" classe="C1">
        </prefixe>
    <prefixe unvoweledform="ف" voweledform="فَ" desc="حرف العطف أو الاستئناف" 
classe="C1">
     </prefixe>
    </prefixes>

解决方案

Looking at the source code for Digester, what it comes down to appears to be this code:

SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware( namespaceAware );
factory.setXIncludeAware( xincludeAware );
factory.setValidating( validating );
factory.setSchema( schema );

Then checking the JavaDoc for SAXParserFactory#setSchema:

A parser must be able to work with any Schema implementation... Throws: UnsupportedOperationException - When implementation does not override this method.

So my guess is the SAXParserFactory implementation your code is receiving does not support schemas in some way.

There are some tips for troubleshooting in the SAXParserFactory.html#newInstance doco, but you can also just find the exact parser class being returned with the following (no Digester code required):

SAXParserFactory factory = SAXParserFactory.newInstance();
System.err.println("SAXParserFactory class is " + factory.getClass().getName());

Also, from the Android SAXParserFactory doco:

UnsupportedOperationException For backward compatibility, when implementations for earlier versions of JAXP is used, this exception will be thrown.

So you may want to check the versions of JAXP etc. you are using.

Update

Given that you do not need schemas, you can try this which may work... instead of letting the digester create the SAXParserFactory for you, create one yourself - that way you can avoid the call to setSchema which looks like it may be the problem:

// create your own SAXParserFactory, but don't call any of the set methods unless you explicitly need to
final SAXParserFactory myfactory = SAXParserFactory.newInstance();

//myfactory.setNamespaceAware( namespaceAware );
//myfactory.setXIncludeAware( xincludeAware );
//myfactory.setValidating( validating );
//myfactory.setSchema( schema );

// create your own Digester and override the getFactory method to return your own factory
Digester digester = new Digester() {
  @Override
  public SAXParserFactory getFactory() {
    return myfactory;
  }
};

// use this digester as normal for the rest of your code...

Not doing any android development at the moment so can't test this, but looks like it could work...

Update 2

So that looked like it fixed the schema problem, and what you have now appears to be a separate class loader issue. That's actually a separate question, but here's a possible hack... bypass the banutils introspection and just process the attributes yourself with a custom rule. This is only really practical because you have fairly simple XML in your example - anything more complicated that that and this approach becomes unworkable:

final List<Prefixe> list = new ArrayList<>();
final SAXParserFactory factory = SAXParserFactory.newInstance();

Digester digester = new Digester() {
  @Override
  public SAXParserFactory getFactory() {
     System.out.println("using custom factory...");
    return factory;
  }
};

digester.addRule("prefixes/prefixe", new Rule() {
  @Override
  public void begin(String namespace, String name, Attributes attributes) throws Exception {
    Prefixe prefixe = new Prefixe();
    prefixe.setUnvoweledform(attributes.getValue("unvoweledform"));
    prefixe.setVoweledform(attributes.getValue("voweledform"));
    prefixe.setDesc(attributes.getValue("desc"));
    prefixe.setClasse(attributes.getValue("classe"));
    list.add(prefixe);
  }
});

digester.parse(...);

Please note that it looks like you have classloader issues somewhere (unless the version of beanutils you have has been crippled in some way?) and I'd strongly recommend you try to get to the bottom of those as they may come back to bite you again and again...

Good luck!

这篇关于与公地沼气池java.lang.UnsupportedOperationException安卓:这分析器不支持规范和QUOT;未知QUOT&;版本&QUOT; 0.0&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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