Venkat SM Venkat SM - 8 months ago 58
HTML Question

HTML to XML Conversion using XSLT in java

Hi Can anyone help me in html to xml conversion using xslt in java.I converted xml to html using xslt in java.This is the code i used for that converstion:

import javax.xml.transform.*;


public class HowToXSLT {

public static void main(String[] args) {

try {

TransformerFactory tFactory = TransformerFactory.newInstance();

Transformer transformer =

( new FileOutputStream("howto.html")));
catch (Exception e) {
e.printStackTrace( );

But i dont know the reverse process of this program that is to convert html to xml? Is there is any jar files available to do that? please help me...

Answer Source

Generally, it isn't possible to "reverse" a transformation, because a transformation in the general case isn't a 1:1 mapping.

For example, if the transformation does this:

<xsl:value-of select= "/x * /x"/>

and we get as result: 16

(and we know that the source XML document had only one element),

it isn't possible to determine from the value 16 whether the source XML document was:


or whether it was:


And the above was only a simple example! :)