2011-12-12 59 views
0

我正在尝试生成Java类来将xml绑定到使用脚轮的对象。这件作品的XML,我想要绑定的是Spring的XML文件,所以我采取了DTD和生成使用蓖麻油提供的工具的XSD,但一旦我尝试生成源文件,我收到以下错误是否可以从spring-beans.dtd生成的spring-beans.xsd生成java源文件?

java.lang.IllegalArgumentException: Duplicate name found as a class member: _key 

这里是我已生成XSD文件:

<?xml version="1.0" encoding="UTF-8"?> 
     <schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="generated.castor.org"> 
<element name="entry"> 
    <complexType> 
     <sequence> 
      <element ref="key" minOccurs="0" /> 
      <choice minOccurs="0"> 
       <element ref="bean" /> 
       <element ref="ref" /> 
       <element ref="idref" /> 
       <element ref="value" /> 
       <element ref="null" /> 
       <element ref="list" /> 
       <element ref="set" /> 
       <element ref="map" /> 
       <element ref="props" /> 
      </choice> 
     </sequence> 
     <attribute name="value-ref" type="string" /> 
     <attribute name="key" type="string" /> 
     <attribute name="value" type="string" /> 
     <attribute name="key-ref" type="string" /> 
    </complexType> 
</element> 
<element name="arg-type"> 
    <complexType mixed="true"> 
     <attribute name="match" type="string" /> 
    </complexType> 
</element> 
<element name="bean"> 
    <complexType> 
     <sequence> 
      <element ref="description" minOccurs="0" /> 
      <choice minOccurs="0" maxOccurs="unbounded"> 
       <element ref="meta" /> 
       <element ref="constructor-arg" /> 
       <element ref="property" /> 
       <element ref="lookup-method" /> 
       <element ref="replaced-method" /> 
      </choice> 
     </sequence> 
     <attribute name="name" type="string" /> 
     <attribute name="id" type="ID" /> 
     <attribute name="class" type="string" /> 
     <attribute name="singleton" default="true"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="factory-method" type="string" /> 
     <attribute name="dependency-check" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="simple" /> 
        <enumeration value="none" /> 
        <enumeration value="objects" /> 
        <enumeration value="all" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="lazy-init" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="autowire-candidate" default="true"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="init-method" type="string" /> 
     <attribute name="autowire" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="no" /> 
        <enumeration value="byName" /> 
        <enumeration value="autodetect" /> 
        <enumeration value="byType" /> 
        <enumeration value="constructor" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="destroy-method" type="string" /> 
     <attribute name="abstract" default="false"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="depends-on" type="string" /> 
     <attribute name="parent" type="string" /> 
     <attribute name="factory-bean" type="string" /> 
    </complexType> 
</element> 
<element name="prop"> 
    <complexType mixed="true"> 
     <attribute name="key" type="string" use="required" /> 
    </complexType> 
</element> 
<element name="beans"> 
    <complexType> 
     <sequence> 
      <element ref="description" minOccurs="0" /> 
      <choice minOccurs="0" maxOccurs="unbounded"> 
       <element ref="import" /> 
       <element ref="alias" /> 
       <element ref="bean" /> 
      </choice> 
     </sequence> 
     <attribute name="default-destroy-method" type="string" /> 
     <attribute name="default-lazy-init" default="false"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="default-init-method" type="string" /> 
     <attribute name="default-dependency-check" default="none"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="simple" /> 
        <enumeration value="none" /> 
        <enumeration value="objects" /> 
        <enumeration value="all" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="default-autowire" default="no"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="no" /> 
        <enumeration value="byName" /> 
        <enumeration value="autodetect" /> 
        <enumeration value="byType" /> 
        <enumeration value="constructor" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
     <attribute name="default-merge" default="false"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
    </complexType> 
</element> 
<element name="props"> 
    <complexType> 
     <sequence> 
      <element ref="prop" minOccurs="0" maxOccurs="unbounded" /> 
     </sequence> 
     <attribute name="merge" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
    </complexType> 
</element> 
<element name="lookup-method"> 
    <complexType> 
     <attribute name="bean" type="string" /> 
     <attribute name="name" type="string" /> 
    </complexType> 
</element> 
<element name="replaced-method"> 
    <complexType> 
     <sequence> 
      <element ref="arg-type" minOccurs="0" maxOccurs="unbounded" /> 
     </sequence> 
     <attribute name="name" type="string" /> 
     <attribute name="replacer" type="string" /> 
    </complexType> 
</element> 
<element name="ref"> 
    <complexType> 
     <attribute name="bean" type="string" /> 
     <attribute name="local" type="IDREF" /> 
     <attribute name="parent" type="string" /> 
    </complexType> 
</element> 
<element name="property"> 
    <complexType> 
     <sequence> 
      <element ref="description" minOccurs="0" /> 
      <element ref="meta" minOccurs="0" maxOccurs="unbounded" /> 
      <choice minOccurs="0"> 
       <element ref="bean" /> 
       <element ref="ref" /> 
       <element ref="idref" /> 
       <element ref="value" /> 
       <element ref="null" /> 
       <element ref="list" /> 
       <element ref="set" /> 
       <element ref="map" /> 
       <element ref="props" /> 
      </choice> 
     </sequence> 
     <attribute name="name" type="string" use="required" /> 
     <attribute name="ref" type="string" /> 
     <attribute name="value" type="string" /> 
    </complexType> 
</element> 
<element name="import"> 
    <complexType> 
     <attribute name="resource" type="string" use="required" /> 
    </complexType> 
</element> 
<element name="meta"> 
    <complexType> 
     <attribute name="key" type="string" use="required" /> 
     <attribute name="value" type="string" use="required" /> 
    </complexType> 
</element> 
<element name="set"> 
    <complexType> 
     <choice minOccurs="0" maxOccurs="unbounded"> 
      <element ref="bean" /> 
      <element ref="ref" /> 
      <element ref="idref" /> 
      <element ref="value" /> 
      <element ref="null" /> 
      <element ref="list" /> 
      <element ref="set" /> 
      <element ref="map" /> 
      <element ref="props" /> 
     </choice> 
     <attribute name="value-type" type="string" /> 
     <attribute name="merge" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
    </complexType> 
</element> 
<element name="null"> 
    <complexType mixed="true" /> 
</element> 
<element name="alias"> 
    <complexType> 
     <attribute name="name" type="string" use="required" /> 
     <attribute name="alias" type="string" use="required" /> 
    </complexType> 
</element> 
<element name="value"> 
    <complexType mixed="true"> 
     <attribute name="type" type="string" /> 
    </complexType> 
</element> 
<element name="constructor-arg"> 
    <complexType> 
     <sequence> 
      <element ref="description" minOccurs="0" /> 
      <choice minOccurs="0"> 
       <element ref="bean" /> 
       <element ref="ref" /> 
       <element ref="idref" /> 
       <element ref="value" /> 
       <element ref="null" /> 
       <element ref="list" /> 
       <element ref="set" /> 
       <element ref="map" /> 
       <element ref="props" /> 
      </choice> 
     </sequence> 
     <attribute name="index" type="string" /> 
     <attribute name="type" type="string" /> 
     <attribute name="ref" type="string" /> 
     <attribute name="value" type="string" /> 
    </complexType> 
</element> 
<element name="description"> 
    <complexType mixed="true" /> 
</element> 
<element name="list"> 
    <complexType> 
     <choice minOccurs="0" maxOccurs="unbounded"> 
      <element ref="bean" /> 
      <element ref="ref" /> 
      <element ref="idref" /> 
      <element ref="value" /> 
      <element ref="null" /> 
      <element ref="list" /> 
      <element ref="set" /> 
      <element ref="map" /> 
      <element ref="props" /> 
     </choice> 
     <attribute name="value-type" type="string" /> 
     <attribute name="merge" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
    </complexType> 
</element> 
<element name="map"> 
    <complexType> 
     <sequence> 
      <element ref="entry" minOccurs="0" maxOccurs="unbounded" /> 
     </sequence> 
     <attribute name="value-type" type="string" /> 
     <attribute name="key-type" type="string" /> 
     <attribute name="merge" default="default"> 
      <simpleType> 
       <restriction base="NMTOKEN"> 
        <enumeration value="default" /> 
        <enumeration value="false" /> 
        <enumeration value="true" /> 
       </restriction> 
      </simpleType> 
     </attribute> 
    </complexType> 
</element> 
<element name="idref"> 
    <complexType> 
     <attribute name="bean" type="string" /> 
     <attribute name="local" type="IDREF" /> 
    </complexType> 
</element> 
<element name="key"> 
    <complexType> 
     <choice> 
      <element ref="bean" /> 
      <element ref="ref" /> 
      <element ref="idref" /> 
      <element ref="value" /> 
      <element ref="null" /> 
      <element ref="list" /> 
      <element ref="set" /> 
      <element ref="map" /> 
      <element ref="props" /> 
     </choice> 
    </complexType> 
</element> 

有没有人遇到了类似的问题,并知道有什么方法可以解决这一问题?

回答

0

对于混凝土脚轮问题,我想你应该提供更多的信息。看起来有一个重复的字段,所以继续并逐个删除每个“键”属性,直到它开始工作。

但是这是一件奇怪的事情,你正试图做。 Spring的DTD/XSD旨在提供XML配置 - 它们不应该代表对象。如果要使用代码而不是xml配置spring,请使用javaconfig

+0

感谢您的建议,我不知道javaconfig存在。不幸的是,我不认为我能够在我的项目中使用这个库。我正在尝试做的是在GUI中包装不同部分的spring文件,以减少非程序员的威胁。 spring文件将从一个单独的项目中访问。现在我正在使用java dom解析器解析spring xml文件,但它看起来好像比必要的代码多得多。 – AgentRegEdit

相关问题