【发布时间】:2011-01-31 22:41:33
【问题描述】:
我有两个 XML 示例要为其编写架构:
示例 1:
<attributes><attribute type="test" value="yes"/></attributes>
示例 2:
<attributes><attribute type="test"><value x="100" y="50">yes</value></attribute></attributes>
示例 3:
<attributes><attribute type="test" value="no"><value x="100" y="50">yes</value></attribute></attributes>
是否有可能有一个适用于这些的架构? 'value' 是一个属性,另一个是元素?
更新 好吧,我想我现在明白我的问题了。
我有这个 XSD:
<xs:complexType name="Attribute">
<xs:sequence >
<xs:element name="value" type="Value" minOccurs="0" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
<xs:attribute name="type" type="xs:string" use="required">
</xs:attribute>
<xs:attribute name="value" type="xs:string" >
</xs:attribute>
</xs:complexType>
但是当我尝试使用 JAXB 从 XSD 生成 java 类时,我得到一个错误:
[xjc] [ERROR] Property "Value" is already defined. Use <jaxb:property> to resolve this conflict.
[xjc] line 275 of file:common.xsd
[xjc] [ERROR] The following location is relevant to the above error
[xjc] line 286 of file:common/common.xsd
[xjc] failure in the XJC task. Use the Ant -verbose switch for more details
我猜这是 JAXB 而不是 XSD 的限制。它将尝试创建两个名为 getValue() 的方法,但都会失败。
【问题讨论】:
-
它是什么让你觉得它不会是可能的?