JAXB schema to Java Different XmlRootElement name and Class name

限于喜欢 提交于 2019-11-29 15:06:14

I suggest you to use this bindings

<bindings version="2.0" xmlns="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc"
    xmlns:annox="http://annox.dev.java.net"
    xmlns:namespace="http://jaxb2-commons.dev.java.net/namespace-prefix">
    <bindings schemaLocation="../your.xsd">

        <bindings node="//xs:element[@name='customer']//xs:complexType">
            <annox:annotate>
                <annox:annotate annox:class="javax.xml.bind.annotation.XmlRootElement"
                    name="customer" namespace="yourNamespaceIfYouWant">
                </annox:annotate>
            </annox:annotate>
            <class name="CustomerRequest"/>
        </bindings>

    </bindings>
</bindings>

Class

@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
    "header"
})
@XmlRootElement(name = "customer", namespace = "yourNamespaceIfYouWant")
public class CustomerRequest
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!