将JAXB类(不是它的对象)转换为xml模板
有没有办法可以将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模板(没有值)
链接地址: http://www.djcxy.com/p/41859.html上一篇: Convert JAXB class (not its object) to xml template
下一篇: WS AXIS2 webservice on WEBSPHERE 6.1 deployment gives java.lang.VerifyError