我想使用 JAXB 2.1 XJC 从 xsd 生成 java 代码。我提供了 xsd 架构,但无法更改它。我想在从 xml 模式生成 java 类时使用 xjc:simple 模式。
在 xsd 中有一些元素:
<xs:any namespace="##other" processContents="lax"/>
正如这里所述: http://jaxb.java.net/guide/Mapping_of__xs_any___.html 我预计这些元素将被绑定到:
@XmlAnyElement(lax=true)
public Object any;
但是当我使用简单绑定模式 xjc:simple 我有:
@XmlAnyElement
protected Element any;
我试图找到一种解决方法,但到处都是据说 xs:any 无需配置即可处理。将 xs:any 元素设置为 java.lang.Object 的唯一方法是在 xsd 中删除 xjc:simple 或将 processContents 更改为“strict”。这些选项现在对我来说都不可接受,因为我无法更改 xml 架构,并且我有一些遗留代码依赖于使用 xjc:simple 模式生成的 java 类,但现在我需要使用 xs:any 元素,我想避免使用 org.w3c.dom.Element 对象。
任何帮助将不胜感激。谢谢。
I want to generate java code from xsd using JAXB 2.1 XJC. I have an xsd schema provided and I can't change it. I would like to use xjc:simple mode while generating java classes from xml schema.
In the xsd there are elements:
<xs:any namespace="##other" processContents="lax"/>
As it is stated here: http://jaxb.java.net/guide/Mapping_of__xs_any___.html I expected that these elements will be binded to:
@XmlAnyElement(lax=true)
public Object any;
but when I use simple binding mode xjc:simple I have:
@XmlAnyElement
protected Element any;
I was trying to find a workaround, but everywhere it's said that xs:any is handled with no configuration. The only way to have xs:any element as java.lang.Object is to drop xjc:simple or change processContents to "strict" in xsd. None of these options are acceptable right now for me as I can't change xml schema and I have some legacy code that depends on java classes generated with xjc:simple mode but now I need to use xs:any element and I would like to avoid using org.w3c.dom.Element objects.
Any help would be very appreciated. Thanks.
发布评论
评论(1)
您可以使用 通配符插件 .highsource.org/display/J2B/JAXB2+Basics+Plugins" rel="noreferrer">JAXB2 基础知识。这允许您自定义宽松/跳过/严格通配符绑定模式:
您不必为此更改架构,您可以通过绑定文件使用此自定义。
You can use the Wildcard plugin from JAXB2 Basics. This allows you to customize lax/skip/strict wildcard binding modes:
You don't have to change the schema for this, you can use this customization via binding files.