是否可以将JAXB类(不是其对象)转换为xml模板。
例如
以下代码取自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); }
在上面的代码中,类Element的对象已被创建为marshall。我的问题是,如果我没有JAXB类的对象,我仍然能够生成xml模板(没有值)