dcsimg
Problem with XML to CSV transformation using JDOM api
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Vineet_Venkatesh
Posted On:   Thursday, March 11, 2004 01:13 AM

Hi Guys! I am facing a problem wherein i am trying to transform an XML using an XSL to a csv format data, using the JDOM api which returns an empty string as the output. Listed below is the code snippet for the transformation which results in an empty string. Could someone please suggest a way to resolve this particular issue. Transformation Code /** This method takes a Document object and a stylesheet and it returns a response after processing the xml using the stylesheet. */ public static ByteArrayOutputStream transform(Document doc,String stylesheetPath)throws TransformationException { OutputStream outStream = null;    More>>

Hi Guys!


I am facing a problem wherein i am trying to transform an XML using an XSL to a csv format data, using the JDOM api which returns an empty string as the output. Listed below is the code snippet for the transformation which results in an empty string.



Could someone please suggest a way to resolve this particular issue.



Transformation Code


/**
This method takes a Document object and a stylesheet and it returns a response after processing the xml using the stylesheet.


*/


public static ByteArrayOutputStream transform(Document doc,String stylesheetPath)throws TransformationException
{


OutputStream outStream = null;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
String sErrorMessage="JDOMHelper::transform";
byte[] byteArray = null;


try
{


Transformer transformer =
TransformerFactory.newInstance().newTransformer(
new StreamSource(stylesheetPath));


JDOMSource req = new JDOMSource(doc);


JDOMResult res = new JDOMResult();


transformer.transform(req,res);


List list = res.getResult();


try
{


XMLOutputter serializer = new XMLOutputter();


String outString = serializer.outputString(list);


System.out.println("

THE OUTPUT STRING
IS:"+outString);


byteArray = outString.getBytes();


bos.write(byteArray);


}


catch (IOException e)


{


System.err.println(e);


}


return bos;


}


catch(Exception tex)
{


String sErrorMsg = sErrorMessage + "Failed to transform
the XML:";


}


}




Sample XML
<?xml version="1.0" encoding="UTF-8"?>
100000000 Yes



Sample XSL



<?xml version="1.0"?>



,



   <<Less
About | Sitemap | Contact