Этот тип проблемы часто возникает, когда тип имеет атрибут и элемент с тем же именем.
schema.xsd
<?xml version="1.0" encoding="UTF-8"?>
<schema
xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://www.example.org/schema"
xmlns:tns="http://www.example.org/schema"
elementFormDefault="qualified">
<element name="foo">
<complexType>
<sequence>
<element name="bar" type="string"/>
</sequence>
<attribute name="bar" type="string"/>
</complexType>
</element>
</schema>
XJC schema.xsd
Когда мы пытаемся создать модель Java из этого XML-схемы, мы получаем следующую ошибку.
parsing a schema...
[ERROR] Property "Bar" is already defined. Use <jaxb:property> to resolve this conflict.
line 11 of file:/Users/bdoughan/Scratch/src/forum16714465/schema.xsd
[ERROR] The following location is relevant to the above error
line 13 of file:/Users/bdoughan/Scratch/src/forum16714465/schema.xsd
binding.xml
JAXB файл связывания может быть использован для настройки классов, которые создаются. Здесь мы будем использовать его для переименования свойства, которое будет соответствовать атрибуту bar
.
<jxb:bindings
xmlns:xs="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="//xs:element[@name='foo']/xs:complexType/xs:attribute[@name='bar']">
<jxb:property name="barAttribute"/>
</jxb:bindings>
</jxb:bindings>
</jxb:bindings>
XJC -b binding.xml schema.xsd
Теперь, когда вы создаете классы Java вы получите класс как:
package org.example.schema;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "", propOrder = {
"bar"
})
@XmlRootElement(name = "foo")
public class Foo {
@XmlElement(required = true)
protected String bar;
@XmlAttribute(name = "bar")
protected String barAttribute;
public String getBar() {
return bar;
}
public void setBar(String value) {
this.bar = value;
}
public String getBarAttribute() {
return barAttribute;
}
public void setBarAttribute(String value) {
this.barAttribute = value;
}
}
Можете ли вы помочь найти решение для Java генерирующая источники из wsdl [wsimport не может генерировать источник java] (http://stackoverflow.com/questions/25893047/wsimport-cant-generate-java-source-error-property-bookingreferenceid-is-a)? он имеет подобную область ... –
Это отличный ответ – Andremoniy