我怎么能转换XML到HTML的android上? [英] How can I transform xml to html on android?

查看:162
本文介绍了我怎么能转换XML到HTML的android上?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是比较新的Java和Android的,在我的Andr​​oid应用程序,我需要得到xml文件,转换并显示用户。

I'm relatively new to java and android, in my android application I need to get xml file, transform it and show to user.

我知道如何解析XML,但我不想对它进行解析后生成视图。我想将其转换为HTML和显示的WebView。

I know how to parse xml, but I don't want to parse it and generate view after. I'd like to transform it to html and display in WebView.

我想在互联网上找到的东西,但无法找到任何东西((

I'm trying to find something on the Internet but can't find anything((

我该怎么办呢?任何意见或链接将AP preciated,

How can I do it? Any ideas or links will be appreciated,

感谢

推荐答案

通常用于XML转换成HTML工具是XSLT。 SO搜索XSLT教程,你会得到一些不错的效果。

The usual tool to use for transforming XML to HTML is XSLT. Search SO for XSLT tutorial and you'll get some good results.

这里是展示一个开发人员如何使用XSLT Android上的另一个问题。
您也可以搜索在Java中使用变压器的例子,如这是很有帮助的文章

Here is another question showing how one developer used XSLT on Android. You can also search for examples of the use of Transformer in Java, as in this helpful article:

// JAXP reads data using the Source interface
Source xmlSource = new StreamSource(xmlFile);
Source xsltSource = new StreamSource(xsltFile);

// the factory pattern supports different XSLT processors
TransformerFactory transFact =
        TransformerFactory.newInstance();
Transformer trans = transFact.newTransformer(xsltSource);

trans.transform(xmlSource, new StreamResult(System.out));

更新:
对于老版本的Andr​​oid的Java API:结果
本文展示了如何使用的 SAX解析器来解析输入XML,然后使用的 XmlSerializer的输出XML。后者可以很容易地输出任何你想要的XHTML。两者都可以,因为API等级1。

Update: For older versions of the Android java API:
This article shows how to use a SAX parser to parse the input XML, then use XmlSerializer to output XML. The latter could easily output whatever XHTML you want. Both are available since API level 1.

不幸的是我没有看到一个办法做到的XPath API 3级,但如果你输入的XML是不是太复杂,你应该能够code自己的转换。我知道你不想分析它,并产生后视图,但如果你的意思是你不想甚至使用的由Android提供的XML解析器,那么我不知道任何替代的。

Unfortunately I don't see a way to do XPath in API level 3, but if your input XML isn't too complex you should be able to code your own transformations. I know you "don't want to parse it and generate view after", but if you mean you don't want to even use an XML parser that's provided by Android, then I don't know of any alternative.

更新2:
我刚刚了解 XOM,它支持XPath 的一个子集。 这个问题显示在Android上使用XOM(编写XML)与API级别4.你会有人充分利用XPath的功能,以及序列化功能。它需要一个小的外部库,XOM的罐子。我不知道这是否与API级别3兼容。

Update 2: I just learned about XOM, which supports a subset of XPath. This question shows someone using XOM on Android (to write XML) with API level 4. You could take advantage of the XPath features, as well as the serialization features. It requires a small external library, XOM's jar. I don't know if it's compatible with API level 3.

这篇关于我怎么能转换XML到HTML的android上?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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