Convert JAXB class (not its object) to xml template
Is there way one can convert JAXB class (not its object) to xml template.
For example
Below code is taken from http://www.javacodegeeks.com/2011/02/jaxb-generate-xml-xsd.html
public static void main(String[] args) throws JAXBException { ObjectFactory factory = new ObjectFactory(); UserT user = factory.createUserT(); user.setUserName("Sanaulla"); ItemT item = factory.createItemT(); item.setItemName("Seagate External HDD"); item.setPurchasedOn("August 24, 2010"); item.setAmount(new BigDecimal("6776.5")); ItemListT itemList = factory.createItemListT(); itemList.getItem().add(item); ExpenseT expense = factory.createExpenseT(); expense.setUser(user); expense.setItems(itemList); JAXBContext context = JAXBContext.newInstance("generated"); JAXBElement element = factory.createExpenseReport(expense); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty("jaxb.formatted.output",Boolean.TRUE); marshaller.marshal(element,System.out); }
In above code object of class Element has been create to marshall. My question is what if I don't have object of JAXB class, will I still be able to generate xml template (with no values)
链接地址: http://www.djcxy.com/p/41860.html上一篇: JAXB自定义异常编组错误