JAXB schema to Java Different XmlRootElement name and Class name

后端 未结 1 1858
粉色の甜心
粉色の甜心 2020-12-11 20:28

I have a xsd schema from which I\'m generating some java classes. I\'m using jaxb for the generation.

I want to be able to generate a class annotated with @Xml

相关标签:
1条回答
  • 2020-12-11 20:59

    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
    
    0 讨论(0)
提交回复
热议问题