JAXB - How to add xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance
- by Anurag
I am using JAXB to create XML file from a result set.
I have created java/ /class files using the xsd with the help of xjc utiliy. Now I am trying to create the xml file using the Marshaller. In the XML file I do not see theh xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attribute with the root tag. My xsd
Below is the code :
public class JAXBConstructor
{
public void generateXMLDocument(File xmlDocument){
try
{
JAXBContext jaxbContext = JAXBContext.newInstance("com");
Marshaller marshaller = jaxbContext.createMarshaller();
marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
com.ObjectFactory factory = new com.ObjectFactory();
USERTASKSImpl userTasks =(USERTASKSImpl)(factory.createUSERTASKS());
USERTASKTypeImpl userTaskType = (USERTASKTypeImpl)(factory.createUSERTASKSTypeUSERTASKType());
userTaskType.setName("zmannan");
userTaskType.setCode("G5023920");
java.util.List userTaskList=userTasks.getUSERTASK();
userTaskList.add(userTaskType);
marshaller.marshal(userTasks, new FileOutputStream("User_Task.xml"));
}
Output of the code : This does not contain the XMLSchema value -
< ?xml version="1.0" encoding="UTF-8" standalone="yes"?
< USER_TASKS xmlns="http://schemas.jpmchase.net/Recertification"
< CodeG5023920< /Code
< Namezmannan< /Name
< /USER_TASK
< /USER_TASKS
Please help how can I add the schema-instance value in the rrot tag.