Android 上有 StAX 实现吗?
我想在 android 1.6 及以上设备中使用 StAX API 实现。那里有任何实施吗?我无法直接使用 jar 文件,因为它给出了有关内部类的问题。如果它不可用,有什么方法可以重新编译实现吗?是否有其他方法可以将 POJO 类直接映射到 XML,反之亦然,请排除 SAX 解析器和 DOM 解析器。
我认为使用 JAXB 可以将 POJO 类映射到 XML,反之亦然。但情况就是这样。考虑这个例子,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cars>
<car registration="abc123">
<brand>BMW</brand>
<description>Sedan</description>
</car>
<car registration="abc123">
<brand>Ferrari</brand>
<description>SportsCar</description>
</car>
</cars>
现在在结果中我想要包含 2 辆车的列表。
另外,JAXB 解析器与 StAX 相比如何?
I want to use StAX API implementation in android 1.6 and above devices. Are there any implementations out there ? I cannot use the jar file directly since it gives issues regarding inner class. If its not available, is there any way I can recompile the implementation ? Is there an alternate way for POJO class to be mapped into XML and vice versa directly, please exclude SAX parser and DOM parser.
I think it is possible for POJO class to be mapped into XML and vice versa using JAXB. But the situation is like this. Consider this example,
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<cars>
<car registration="abc123">
<brand>BMW</brand>
<description>Sedan</description>
</car>
<car registration="abc123">
<brand>Ferrari</brand>
<description>SportsCar</description>
</car>
</cars>
Now in the result I want List which has the 2 cars in it.
Also how does JAXB parser fare against StAX ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
据我所知, Woodstox 和 Aalto 应该可以在 Android 上运行。 Aalto 是 Java 平台上最快的符合 XML 解析器(如果这很重要的话); Woodstox 支持最广泛的 XML 构造(从完整的 DTD 处理到 RelaxNG/XML 模式验证)。
要将 POJO 绑定到 XML,您还可以考虑 Jackson 扩展 jackson-xml-databind:虽然 Jackson 主要是 JSON 处理器,但扩展支持 XML 的 JAXB 样式数据绑定。并且比 JAXB 参考实现更快(请参阅 jvm-serializers benchmark)。
这也应该适用于 Android(Jackson 本身是 Android 上第一个 JSON 解析器)。
As far as I know, both Woodstox and Aalto should work on Android. Aalto is the single fastest conforming XML parser on Java platform, if that matters; and Woodstox supports widest range of XML constructs (from full DTD handling to RelaxNG/XML Schema validation).
For binding POJOs to XML, you could also consider Jackson extension jackson-xml-databind: while Jackson is mainly JSON processor, extension supports JAXB-style data binding for XML. And does it faster than JAXB reference implementation (see jvm-serializers benchmark).
This also should work on Android (Jackson itself is nr 1 JSON parser on Android).
因此,您真正想要“将 POJO 映射到 XML,反之亦然”的是 简单 XML 库。您可以在 Android 1.5 及以上的每个版本上使用它。
我什至写了一篇 博客文章解释如何将其包含在您的项目之一中。
So what you really want to "map POJOs into the XML and vice versa" is the Simple XML Library. You can use it with every version of Android from 1.5 up.
I even wrote a blog post explaining how to include it in one of your projects.