"找不到合适的SAX2解析器"当我试图解析XML与XOM教程 [英] "Could not find a suitable SAX2 parser" when i try parsing XML with XOM Tutorial

查看:606
本文介绍了"找不到合适的SAX2解析器"当我试图解析XML与XOM教程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找到一个简单的办法让我的Andr​​oid应用程序的XML内容。我给XOM一试。创建XML是没有问题的,但是当我尝试分析一些......模拟器崩溃了强制关闭。我不知道去哪里找。

我在清单中设置网络权限。

在调试/变量,我可以看到的找不到合适的SAX2解析器,然后在logcat中的东西一样

  12月7号至22日:27:51.565:信息/的System.out(683):调试器已落户(1337)
12月7日至22日:27:52.034:信息/ dalvikvm(683):找不到方法org.apache.xerces.impl.Version.getVersion,从方法nu.xom.Builder引用< clinit>
12月7日至22日:27:52.034:WARN / dalvikvm(683):VFY:无法解析静态方法2371:Lorg /阿帕奇/的Xerces / IMPL /版; .getVersion()Ljava /朗/字符串;
12月7日至22日:27:52.044:DEBUG / dalvikvm(683):VFY:更换运code 0x71在0x000f
12月7日至22日:27:52.044:DEBUG / dalvikvm(683):VFY:死$ C $在LNU / XOM /生成器ç0x0012-0049;< clinit>。 ()V
12月7日至22日:27:52.094:WARN / dalvikvm(683):无法解析LNU的超/ XOM / XML1_0Parser; (402)
12月7日至22日:27:52.094:WARN / dalvikvm(683):类的链接LNU / XOM / XML1_0Parser;失败
12月7日至22日:27:52.104:ERROR / dalvikvm(683):找不到类的nu.xom.XML1_0Parser,从法nu.xom.Builder.findParser引用
12月7日至22日:27:52.104:WARN / dalvikvm(683):VFY:无法解析新的实例191(LNU​​ / XOM / XML1_0Parser;)在LNU / XOM /生成器;
12月7日至22日:27:52.104:DEBUG / dalvikvm(683):VFY:更换运code输入0x22为0x0000
12月7日至22日:27:52.114:DEBUG / dalvikvm(683):VFY:死$ C $在LNU / XOM /生成器ç0x0002-0007; .findParser(Z)Lorg / XML / SAX / XMLReader的;
12月7日至22日:27:52.554:WARN / dalvikvm(683):无法解析LNU的超/ XOM / JDK15XML1_0Parser; (8)
12月7日至22日:27:52.554:WARN / dalvikvm(683):类的链接LNU / XOM / JDK15XML1_0Parser;失败
12月7日至22日:27:58.441:WARN / ActivityManager(64):启动超时已过期,放弃唤醒锁!
12月7日至22日:27:58.996:WARN / ActivityManager(64):活动空闲超时时间为HistoryRecord {44fdcb80 com.xb.xomtest /。主要}
 

有一件事,我不明白的是警告,当我添加的jar到我的构建路径。不知道的东西,是因为有是:

  [2011-07-22 14点38分13秒 -  XOM]霉素警告:忽略InnerClasses属性匿名内部类
(nu.xom.Element $ 1)不来的
相关EnclosingMethod属性。这个类可能是由一个生产
编译器并没有针对现代.class文件格式。推荐
的解决方案是重新编译从源的类,使用最多的最新的编译器
并且不指定任何-target类型选项。忽视的后果
这个警告是在此类反射操作将不正确
表明它是*不*内部类。
 

在code:

 包com.xb.xomtest;

进口java.io.IOException异常;

进口nu.xom.Builder;
进口nu.xom.Document;
进口nu.xom.ParsingException;
进口android.app.Activity;
进口android.os.Bundle;

公共类主要的扩展活动{

    / **第一次创建活动时调用。 * /
    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.main);

        尝试 {
              构建分析器=新生成器();
              文档的文档= parser.build(http://www.cafeconleche.org/);
            }
            赶上(ParsingException前){
              //System.err.println("Cafe CON莱什是畸形的今天多么尴尬)。!;
            }
            赶上(IOException异常前){
              //System.err.println("Could无法连接到咖啡欧蕾该网站可能已关闭)。;
            }


    }
}
 

解决方案

的XOM罐子不,本身,包括你需要的一切 - 显然不包括在合适的人名单的标准Android解析器<。 / P> http://www.xom.nu/install.xhtml 摘录P>

的Java 1.3和更早的版本不具有一个内置的XML解析器,以便在这些环境中你还需要安装XOM的支持库,其中包括xalan.jar,xercesImpl.jar,normalizer.jar和XML-的API的.jar,并且被发现在lib目录中。随XOM的版本是相当快一点,比那些捆绑了JDK车少,所以你可能想使用它们,即使在Java 1.4中和以后。

有关基本解析,将xercesImpl.jar随着XOM-1.2.7.jar似乎是不够的 - 我的code, 其中有(抱怨缺少SAX2解析器)现在分析输入OK了同样的问题。

我得到关于内部类相同的Dx警告,这样就不会出现致命的: - )

I'm trying to find a simple way to get XML content in my Android app. I gave XOM a try. Creating XML is no problem, but when i try to parse some... the emulator crashes with a force close. I have no idea where to look.

I have the internet permissions set in the manifest.

In debug/variables i can see "Could not find a suitable SAX2 parser" and in logcat something the same

07-22 12:27:51.565: INFO/System.out(683): debugger has settled (1337)
07-22 12:27:52.034: INFO/dalvikvm(683): Could not find method org.apache.xerces.impl.Version.getVersion, referenced from method nu.xom.Builder.<clinit>
07-22 12:27:52.034: WARN/dalvikvm(683): VFY: unable to resolve static method 2371: Lorg/apache/xerces/impl/Version;.getVersion ()Ljava/lang/String;
07-22 12:27:52.044: DEBUG/dalvikvm(683): VFY: replacing opcode 0x71 at 0x000f
07-22 12:27:52.044: DEBUG/dalvikvm(683): VFY: dead code 0x0012-0049 in Lnu/xom/Builder;.<clinit> ()V
07-22 12:27:52.094: WARN/dalvikvm(683): Unable to resolve superclass of Lnu/xom/XML1_0Parser; (402)
07-22 12:27:52.094: WARN/dalvikvm(683): Link of class 'Lnu/xom/XML1_0Parser;' failed
07-22 12:27:52.104: ERROR/dalvikvm(683): Could not find class 'nu.xom.XML1_0Parser', referenced from method nu.xom.Builder.findParser
07-22 12:27:52.104: WARN/dalvikvm(683): VFY: unable to resolve new-instance 191 (Lnu/xom/XML1_0Parser;) in Lnu/xom/Builder;
07-22 12:27:52.104: DEBUG/dalvikvm(683): VFY: replacing opcode 0x22 at 0x0000
07-22 12:27:52.114: DEBUG/dalvikvm(683): VFY: dead code 0x0002-0007 in Lnu/xom/Builder;.findParser (Z)Lorg/xml/sax/XMLReader;
07-22 12:27:52.554: WARN/dalvikvm(683): Unable to resolve superclass of Lnu/xom/JDK15XML1_0Parser; (8)
07-22 12:27:52.554: WARN/dalvikvm(683): Link of class 'Lnu/xom/JDK15XML1_0Parser;' failed
07-22 12:27:58.441: WARN/ActivityManager(64): Launch timeout has expired, giving up wake lock!
07-22 12:27:58.996: WARN/ActivityManager(64): Activity idle timeout for HistoryRecord{44fdcb80 com.xb.xomtest/.main}

One thing that i don't get is the warning when i add the jar to my buildpath. Don't know if something has to do with that:

[2011-07-22 14:38:13 - XOM] Dx warning: Ignoring InnerClasses attribute for an anonymous inner class
(nu.xom.Element$1) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

The code:

package com.xb.xomtest;

import java.io.IOException;

import nu.xom.Builder;
import nu.xom.Document;
import nu.xom.ParsingException;
import android.app.Activity;
import android.os.Bundle;

public class main extends Activity {

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        try {
              Builder parser = new Builder();
              Document doc = parser.build("http://www.cafeconleche.org/");
            }
            catch (ParsingException ex) {
              //System.err.println("Cafe con Leche is malformed today. How embarrassing!");
            }
            catch (IOException ex) {
              //System.err.println("Could not connect to Cafe con Leche. The site may be down.");
            }


    }
}

解决方案

The xom jar doesn't, by itself, include everything you need - and apparently doesn't include the standard android parser in its list of suitable ones.

excerpt from http://www.xom.nu/install.xhtml:

"Java 1.3 and earlier do not have a built-in XML parser so in these environments you'll also need to install XOM's supporting libraries. These include xalan.jar, xercesImpl.jar, normalizer.jar, and xml-apis.jar, and are found in the lib directory. The versions shipped with XOM are quite a bit faster and less buggy than the ones bundled with the JDK, so you may well want to use them even in Java 1.4 and later. "

For basic parsing, adding xercesImpl.jar along with xom-1.2.7.jar appears to be sufficient - my code, which had the same problem (complaining about a missing sax2 parser) now parses the input OK.

I get the same Dx warning about inner classes, so that doesn't appear to be fatal :-).

这篇关于&QUOT;找不到合适的SAX2解析器&QUOT;当我试图解析XML与XOM教程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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