开发者

Customize JAXB 2.0 generated method names from a xsd:choice element

I'm trying to figure out how to customize a method name that's being generated by JAXB 2.1.12. I have an epic XML schema (that is not in my control), and it contains a group with a choice element that contains about 200 other elements. So when I'm generating the JAXB classes, the get() method that is created is rather unhelpful - it ends up being something like "getElement1AndElement2AndElement3()".

I'd 开发者_如何学Pythonlike to rename the get() method to be something better, but I can't figure out exactly how to do that. I know in the tutorial it describes customizing class names by using on an element.

I found a really old article (http://onjava.com/pub/a/onjava/2003/12/10/jaxb.html?page=2) that describes attaching a "name" attribute to a element, which seems to be what I need to do. Unfortunately, I think that article refers to a 1.x JAXB version, and the name attribute is no longer valid in a choice element as of JAXB 2.0.

So does anybody know how I can customize the method name that gets generated? Please let me know if examples or any other information would be helpful, or if what I'm trying to do just isn't possible.

Thanks!


I've tried with the example exposed in the link you provide and the following binding.xjb works:

<jxb:bindings version="1.0"
    xmlns:jxb="http://java.sun.com/xml/ns/jaxb"
    xmlns:xs="http://www.w3.org/2001/XMLSchema">
    <jxb:bindings>
      <jxb:bindings schemaLocation="po4.xsd" node="/xs:schema/xs:element[@name='Widgets']//xs:complexType//xs:choice">
            <jxb:property name="Shapes"/>
        </jxb:bindings>
    </jxb:bindings>
</jxb:bindings>

I use JAXB 2.1.12 as well.

I hope it helps.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜