从xsd:choice元素自定义JAXB 2.0生成的方法名称 [英] Customize JAXB 2.0 generated method names from a xsd:choice element

查看:81
本文介绍了从xsd:choice元素自定义JAXB 2.0生成的方法名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在试图弄清楚如何自定义由JAXB 2.1.12生成的方法名称。我有一个史诗般的XML模式(不在我的控制之下),它包含一个包含一个包含大约200个其他元素的choice元素的组。因此,当我生成JAXB类时,创建的get()方法相当无用 - 最终会出现类似getElement1AndElement2AndElement3()的内容。

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我想将get()方法重命名为更好的东西,但我无法弄明白该怎么做。我知道在教程中,它描述了使用自定义类名称在元素上。

I'd like 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.

我发现了一篇非常古老的文章( http://onjava.com/pub/a/onjava/2003/12/10/jaxb.html?page=2 )将name属性附加到元素,这似乎是我需要做的。不幸的是,我认为该文章引用了1.x JAXB版本,并且name属性在JAXB 2.0的选择元素中不再有效。

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.

谢谢!

推荐答案

我尝试过您提供的链接中公开的示例,以及以下binding.xjb的工作原理:

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>

我也使用JAXB 2.1.12。

I use JAXB 2.1.12 as well.

我希望它有所帮助。

这篇关于从xsd:choice元素自定义JAXB 2.0生成的方法名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆