Thursday, May 28, 2009

Translating XML with XSL in Java

I do not consider the codes in this blog entry as intensive as other entries. This is just merely an example to show you how to translate a XML document with a XSL stylesheet in a Java class. It could be a very handy tool for some Java developers out there that want to translate a given XML content into another completely different XML content on the fly.
Do not forget to set the encoding of your Java codes to UTF-8 if you are manipulating non-English XML content - for example, Traditional Chinese, Simplified Chinese, Russian, Korean or Japanese - if you would want to see the output in your Eclipse IDE, which is my current IDE to write Java codes.

The usefulness of this approach is that you do not need to include a reference of a XSL file in the XML, say for example,

<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" href="myXMLstylesheet.xsl"?>
<catalog/>

Hope you have fun trying this out! :)

0 comments:

Post a Comment