I have the following xml:
<?xml version="1.0" encoding="UTF-8"?>
<roots xmlns="http://www.test.com/test/rest/v1">
<root>
<name>james</name>
</root>
</roots>
I want to generate the JAXB classes for the above xml and add the name space (xmlns="http://www.test.com/test/rest/v1"
) dynamically while marshaling. I could able to generate the JAXB classes, but not able to add the namespace dynamically. I tried with the following code, but it's not working. Any idea on how to do that?
JAXBContext jaxbContext = JAXBContext.newInstance("com.test");
XMLStreamWriter xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(inputSchema);
xmlStreamWriter.setPrefix("xmlns", "http://www.test.com/test/rest/v1");
Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
jaxbMarshaller.marshal(roots, xmlStreamWriter);