How to generate @XmlRootElement Classes for Base Types in XSD?

前端 未结 2 1612
抹茶落季
抹茶落季 2020-12-05 10:29

I am having some issues with generating Java Classes with appropriate JAXB annotations from an XSD using XJC.

I have a relatively simple XSD file defining my XML sch

相关标签:
2条回答
  • 2020-12-05 11:03

    This question references a blog post by Kohsuke Kawaguchi, formerly worked on the JAX-B or JAX-WS RI, that talks about the RI's decision making process and lack of clarity on this issue in the spec.

    The blog post mentions that the simple binding feature is part of the RI. Are you using the RI to generate your code?

    0 讨论(0)
  • 2020-12-05 11:16

    Just bind using xjb-file:

    <?xml version="1.0"?>
    <jxb:bindings version="1.0" xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xjc="http://java.sun.com/xml/ns/jaxb/xjc" jxb:extensionBindingPrefixes="xjc" xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <jxb:bindings schemaLocation="path/to/myschema.xsd" node="/xs:schema">
        <jxb:globalBindings>
          <xjc:simple />
        </jxb:globalBindings>
      </jxb:bindings>
    </jxb:bindings>
    

    And don't forget to define element of the same type:

    <xs:complexType name="Artifact" />
    <xs:element name="artifact" type="Artifact">
    
    0 讨论(0)
提交回复
热议问题