i need to add xsl code to xml file



now i am trying to add xsl style sheet to xml file using jaxbMarshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders",xslStylesheet); but it doesnt write it in the file this is my code



public static void main(String[] args)
{

account customer = new account();
customer.setId("100");
customer.setName("jack");
customer.setAccNumber("29");
customer.setCurrency("USD");

try
{
String xslStylesheet = "<?xml-stylesheet type='text/xsl' href='test.xsl'?>";
File file = new File("account.xml");
JAXBContext jaxbContext = JAXBContext.newInstance(account.class);
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

jaxbMarshaller.setProperty("com.sun.xml.internal.bind.xmlHeaders",xslStylesheet);
jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
jaxbMarshaller.marshal(customer, file);
jaxbMarshaller.marshal(customer, System.out);

}
catch (JAXBException e)
{
System.out.println("error ");
e.printStackTrace();
}

No comments:

Post a Comment