我想从两个不同的XML生成两组类,一个类具有相同的名称-TAG。
<templates xmlns="http://xxxxxxxxxxx.xx.xxx.xxx">
<template name="XXXXXXXXXXXXXXXXXXXXX">
<tag id="XXXXXXXXXXX">
<tag id="XXXXXXX" value="XXXXXXXXX" />
</tag>
<tag id="YYY" value="YYYYY" />
</template>
</templates>
该XML的和xsd文件
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://xxxxxxxxxxx.xx.xxx.xxx"
xmlns:tns="http://xxxxxxxxxxx.xx.xxx.xxx">
<xsd:element name="templates" type="tns:Templates"/>
<xsd:complexType name="Tag">
<xsd:sequence>
<xsd:element type="tns:Tag" name="tag"/>
</xsd:sequence>
<xsd:attribute type="xsd:string" name="id"/>
</xsd:complexType>
<xsd:complexType name="Template">
<xsd:sequence>
<xsd:element type="tns:Tag" name="tag" maxOccurs="unbounded"/>
</xsd:sequence>
<xsd:attribute type="xsd:string" name="name"/>
</xsd:complexType>
<xsd:complexType name="Templates">
<xsd:sequence>
<xsd:element type="tns:Template" name="template"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>
以及其他具有相同元素名称的XML
<?xml version="1.0" encoding="UTF-8"?>
<keys>
<key label="XXXXXXXXXXXXXXX">
<tag id="YYYYY" />
<tag id="ZZZZZZZZZ" />
</key>
</keys>
使用另一个xml。
要生成类,我使用maven依赖项:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>xjc_pos</id>
<goals>
<goal>xjc</goal>
</goals>
<configuration>
<packageName>ru.bpc.cg.cainterface</packageName>
<generateEpisode>false</generateEpisode>
<clearOutputDir>false</clearOutputDir>
</configuration>
</execution>
</executions>
<configuration>
<outputDirectory>src/main/java</outputDirectory>
<sources>
<source>src/main/resources/ru/bpc/cg/cainterface/caTemplates.xsd</source>
<source>src/main/resources/ru/bpc/cg/storagehandler/keyStorage.xsd</source>
</sources>
</configuration>
</plugin>
在mvn clean package之后,我出现了一个错误:
org.xml.sax.SAXParseException: A class/interface with the same name "com.xxxxxxxxxxxxx.Tag" is already in use. Use a class customization to resolve this conflict.
如何解决此冲突?可能存在从一个xsd到另一个具有相同类定义的链接。