JAXB 编译问题 - [错误] 属性“任何"已经定义 [英] JAXB Compiling Issue - [ERROR] Property "Any" is already defined
问题描述
我正在尝试为 xccdf-1.1.4.xsd 创建 JAXB 绑定,这是一个标准架构,可以从 XCCDF 架构位置
I am trying to create JAXB binding for xccdf-1.1.4.xsd which is a standard schema that can be obtain from XCCDF Schema Location
我目前使用 EclipseLink MOXy 作为我的 JAXB 实现,因为我喜欢它也可以生成 JSON 绑定的事实.
I am currently using EclipseLink MOXy as my JAXB implementation since I like the fact that it can also generate JSON bindings as well.
我修复了几次使用外部绑定 XML 遇到臭名昭著的[ERROR] 属性值"已定义"错误的情况,现在我遇到了错误
I fixed couple of occasion where I hit the infamous "[ERROR] Property "value" is already defined" error using an external binding XML, and now I am hitting an error on
[ERROR] Property "Any" is already defined. Use <jaxb:property> to resolve this conflict.
line 441 of file:/home/dchu/Playground/Java/eclipselink_moxy/xccdf_1.1.4/xccdf-1.1.4.xsd
[ERROR] The following location is relevant to the above error
line 444 of file:/home/dchu/Playground/Java/eclipselink_moxy/xccdf_1.1.4/xccdf-1.1.4.xs
以下是发生错误的 XML 架构中的行的片段.
Below is a snippet of the line in the XML schema where the error occurred.
<xsd:sequence>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:any namespace="http://purl.org/dc/elements/1.1/"
minOccurs="1" maxOccurs="unbounded"/>
<xsd:any namespace="http://checklists.nist.gov/sccf/0.1"
processContents="skip"
minOccurs="1" maxOccurs="unbounded"/>
</xsd:choice>
</xsd:sequence>
有人知道这里有什么问题吗?谢谢!
Does anyone knows what could be wrong here? Thanks!
推荐答案
您可以使用外部绑定文件重命名任何属性之一.
You can use an external bindings file to rename one of the any properties.
binding.xml
<jxb:bindings xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:jxb="http://java.sun.com/xml/ns/jaxb" version="2.1">
<jxb:bindings schemaLocation="schema.xsd">
<jxb:bindings
node="//xsd:complexType[@name='foo']/xsd:sequence/xsd:choice/xsd:any[@namespace='http://checklists.nist.gov/sccf/0.1']">
<jxb:property name="any2" />
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
XML 架构 (schema.xsd)
以下是您的 XML 架构的简化版本:
Below is a simplified version of your XML schema:
<?xml version="1.0" encoding="UTF-8"?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/schema"
xmlns="http://www.example.org/schema"
elementFormDefault="qualified">
<xsd:complexType name="foo">
<xsd:sequence>
<xsd:choice minOccurs="1" maxOccurs="1">
<xsd:any namespace=""
minOccurs="1" maxOccurs="unbounded" />
<xsd:any namespace="http://checklists.nist.gov/sccf/0.1"
processContents="skip" minOccurs="1" maxOccurs="unbounded" />
</xsd:choice>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
XJC 电话
以下是如何利用外部绑定文件进行 XJC 调用.
Below is how you make an XJC call that leverages an external binding file.
xjc -b binding.xml schema.xsd
生成的类 (Foo)
package org.example.schema;
import java.util.*;
import javax.xml.bind.annotation.*;
import org.w3c.dom.Element;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "foo", propOrder = {
"any",
"any2"
})
public class Foo {
@XmlAnyElement(lax = true)
protected List<Object> any;
@XmlAnyElement
protected List<Element> any2;
public List<Object> getAny() {
if (any == null) {
any = new ArrayList<Object>();
}
return this.any;
}
public List<Element> getAny2() {
if (any2 == null) {
any2 = new ArrayList<Element>();
}
return this.any2;
}
}
这篇关于JAXB 编译问题 - [错误] 属性“任何"已经定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!