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

I am using JAXB to create an XML file from a result set.

I created java // class files using xsd using xjc utiliy. Now I am trying to create an xml file using Marshaller. In the XML file, I do not see the xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" attribute xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" with the root tag.

 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")); } 

Code output: It does not contain XMLSchema value -

 <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <USER_TASKS xmlns="http://schemas.jpmchase.net/Recertification"> <USER_TASK> <Code>G5023920</Code> <Name>zmannan</Name> </USER_TASK> </USER_TASKS> 

Please help me how to add the value of a schema instance to the root tag.

+4
source share

Source: https://habr.com/ru/post/1310106/


All Articles