JAXB - How to add xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance

Posted by Anurag on Stack Overflow See other posts from Stack Overflow or by Anurag
Published on 2010-05-18T11:16:47Z Indexed on 2010/05/18 11:20 UTC
Read the original article Hit count: 610

Filed under:
|

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"> < Code>G5023920< /Code> < Name>zmannan< /Name> < /USER_TASK> < /USER_TASKS>

Please help how can I add the schema-instance value in the rrot tag.

© Stack Overflow or respective owner

Related posts about jaxb

Related posts about marshalling