简体   繁体   English

JAXB多个XSD

[英]JAXB multiple xsd

I have two XSD that I generated through JAXB's xjc command. 我有两个通过JAXB的xjc命令生成的XSD。

http://www.imsglobal.org/xsd/imscp_v1p1.xsd and http://www.mmtech.ru/adlcp_v1p3.xsd http://www.imsglobal.org/xsd/imscp_v1p1.xsdhttp://www.mmtech.ru/adlcp_v1p3.xsd

I am trying to use the Item object from the first xsd like 我正在尝试使用第一个xsd中的Item对象
ItemType item = factory.createItemType();
DataType dataType = factory.createDataType();
MapType mapType = factory.createMapType();
dataType.getMap().add(mapType);
item.getAny().add(dataType);

Note that DataType and MapType are both from the two XSD. 请注意,DataType和MapType都来自两个XSD。

I can generate the xml file expect for one problem, it is giving the error 我可以生成一个问题的xml文件,它给出了错误

Caused by: com.sun.istack.SAXException2: unable to marshal type "packagename.DataType" as an element because it is missing an @XmlRootElement annotation 引起原因:com.sun.istack.SAXException2:由于缺少@XmlRootElement批注,因此无法将类型“ packagename.DataType”作为元素编组

So I tried adding the @XmlRootElement to the DataType class and instead of it creating ns2:dataType, it creates the XML below. 因此,我尝试将@XmlRootElement添加到DataType类中,而不是创建ns2:dataType,而是在下面创建XML。

        <item>
            <dataType>
                <ns2:map targetID="targetid" writeSharedData="false"/>
            </dataType>
        </item>

Please help. 请帮忙。 Thank you 谢谢

to answer my own question. 回答我自己的问题。

We should convert the DataType class to a JAXBElement. 我们应该将DataType类转换为JAXBElement。

JAXBElement dataTypeElement = factory.createData(dataType);
item.getAny().add(dataTypeElement);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM