Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The usual tool to use for transforming XML to HTML is XSLT. Search SO for XSLT tutorial and you'll get some good results.</p> <p><a href="https://stackoverflow.com/questions/3718381/xslt-transforming-performance">Here is another question</a> showing how one developer used XSLT on Android. You can also search for examples of the use of <a href="http://developer.android.com/reference/javax/xml/transform/Transformer.html" rel="nofollow noreferrer">Transformer</a> in Java, as in <a href="http://www.oreillynet.com/pub/a/oreilly/java/news/javaxslt_0801.html" rel="nofollow noreferrer">this helpful article</a>:</p> <pre><code>// 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)); </code></pre> <p><strong>Update:</strong> For older versions of the Android java API:<br> <a href="http://ibm.com/developerworks/opensource/library/x-android/index.html" rel="nofollow noreferrer">This article</a> shows how to use a <a href="http://developer.android.com/reference/javax/xml/parsers/SAXParser.html" rel="nofollow noreferrer">SAX parser</a> to parse the input XML, then use <a href="http://developer.android.com/reference/org/xmlpull/v1/XmlSerializer.html" rel="nofollow noreferrer">XmlSerializer</a> to output XML. The latter could easily output whatever XHTML you want. Both are available since API level 1.</p> <p>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.</p> <p><strong>Update 2:</strong> I just learned about <a href="http://www.xom.nu/" rel="nofollow noreferrer">XOM, which supports a subset of XPath</a>. <a href="https://stackoverflow.com/questions/2290945/writing-xml-on-android">This question</a> 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.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload