With the
java XML transformer you can transform the XML documents into other
forms. The most common imports that are needed to work with the transformer
class in your java program include,
_______________________________________________
_______________________________________________
import
java.io.*;
. . .
. . .
import javax.xml.parsers.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
To create
a transformer object you have to use the TransformerFactory's newTransformer()
method. With this method you can create an instance of the transformer
class.
TransformerFactory
transfact = TransformerFactory.newInstance();
Transformer trans = transformerFactory.newTransformer();
. . .
. . .
trans.transform(src, res);
The above
code snippet will do the transformation needed in your java program.
The transform method of the transformer object takes two parameters
called the source and the result. In the above code snippet the 'src'
is a DOMSource object and the 'res' is a StreamResult object. These
two can be created using the code as given below,
DOMSource
src = new DOMSource(docObj);
StreamResult res = new StreamResult(fileOutStr);
In the
above code the 'docObj' is the document object and the 'fileOutStr'
is the FileOutputStream.
Lots of
examples of using the transformer object is available in the internet.