【发布时间】:2011-12-15 21:00:26
【问题描述】:
我正在尝试使用 Visio XML Schema 编组一个文件,该文件由 3 个模式文件组成,并在使用 XJC 生成 java 源代码时生成三个包:
- com.microsoft.schemas.visio._2003.core
- com.microsoft.schemas.visio._2006.extension
- com.microsoft.schemas.office.visio._2010.extension
根元素是VisioDocument,我使用的所有类都在2003 包中。
这是我编组 XML 文件的方法:
VisioDocumentType visioDoc = new VisioDocumentType();
... manipulated here ...
JAXBContext jc = JAXBContext.newInstance("com.microsoft.schemas.visio._2003.core");
Marshaller m = jc.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
m.marshal(new JAXBElement<VisioDocumentType>(new QName("uri","local"), VisioDocumentType.class, visioDoc), bw);
执行时,我收到此错误:
javax.xml.bind.MarshalException
- with linked exception:
[com.sun.istack.internal.SAXException2: unable to marshal type "com.microsoft.schemas.visio._2003.core.PagePropsType" as an element because it is missing an @XmlRootElement annotation]
我正在使用PagePropsType,但它不是根元素。为什么 JAXB 会这么认为?
【问题讨论】:
-
你在注释上设置
com.microsoft.schemas.visio._2003.core.PagePropsType实例的属性如何? -
@XmlAccessorType(XmlAccessType.FIELD) @XmlType(name = "PageProps_Type", propOrder = { "pageWidthOrPageHeightOrShdwOffsetX" })这就是你要找的吗? -
我的意思是您将实例设置到的属性,而不是
PagePropsType本身。 -
这是我要添加到的对象:snipt.org/qKT3