我正在为我的服务创建 xsd 文件,并希望从中生成类。但想法强调了复杂类型,并且在生成类时 - 发生[错误]欠定义元素声明StepResponse。我查看了示例here和 here ,但在我的情况下它不起作用。这是代码:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema" targetNamespace="http://com/tictocsoa/ws" elementFormDefault="qualified">
<element name="StepRequest" type="GameStep"/>
<element name="StepResponse" type="GameStep"/>
<element name="StepsResponse" type="GameSteps"/>
<complexType name="GameStep">
<sequence>
<element name="gameId" type="int"/>
<element name="num" type="int"/>
<element name="cell" type="int"/>
</sequence>
</complexType>
<complexType name="GameSteps">
<sequence maxOccurs="unbounded" minOccurs="0">
<element name="steps" type="GameStep"/>
</sequence>
</complexType>
</schema>
为什么找不到这个类型?我只想生成 2 个类:第一个类用于一个对象,另一个类用于它的列表(分别用于 getById 和 getAll 方法)。另一个问题 - 也许最好为两者创建一个类?
附注使用 jaxb-ri-2.2.7 生成
最佳答案
您错过了命名空间的前缀,请尝试类似的操作:
<?xml version="1.0" encoding="UTF-8"?>
<schema xmlns="http://www.w3.org/2001/XMLSchema"
targetNamespace="http://com/tictocsoa/ws"
elementFormDefault="qualified"
xmlns:tts="http://com/tictocsoa/ws">
<element name="StepRequest" type="tts:GameStep"/>
<element name="StepResponse" type="tts:GameStep"/>
<element name="StepsResponse" type="tts:GameSteps"/>
<complexType name="GameStep">
<sequence>
<element name="gameId" type="int"/>
<element name="num" type="int"/>
<element name="cell" type="int"/>
</sequence>
</complexType>
<complexType name="GameSteps">
<sequence maxOccurs="unbounded" minOccurs="0">
<element name="steps" type="tts:GameStep"/>
</sequence>
</complexType>
</schema>
关于java - 无法从 xsd 生成对象列表的类,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21336771/