Is this XML example possible to write a schema for?
I have two XML examples that I want to write a schema for:
Example 1:
<attributes>
<attribute type="test" value="yes"/>
</attributes>
Example 2:
<attributes>
<attribute type="test">
<value x="100" y="50">yes</value>
</attribute>
</attributes>
Example 3:
<attributes>
<attribute type="test" value="no">
<value x="100" y="50">yes</value>
</attribute>
</attributes>
Is it possible to have a schema that works for these? With 'value' being an attribute in one and an element in the other?
Update Right, I think I understand my problem now.
I have this XSD:
<xs:complexType name="Attribute">
<xs:sequence >
<xs:element name="value" type="Value" minOccurs="0" maxOccurs="unbounded">
</xs:element>
</xs:sequence>
开发者_Python百科 <xs:attribute name="type" type="xs:string" use="required">
</xs:attribute>
<xs:attribute name="value" type="xs:string" >
</xs:attribute>
</xs:complexType>
But when I try to use JAXB to generate java classes from the XSD I get an error:
[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
I guess this is a limitation in JAXB rather than the XSD. It will try to create two methods called getValue() which will fail.
The answer is 'yes', but if you want an if/else statement in the schema based on the value
attribute then the answer is 'no'. You just create the xsd with all of the attributes and elements values as optional and the document will validate fine. What an xsd validation will do for you is to tell you that document is valid under the rules specified in the schema, but what it does not do is process the data inside document like the actual yes
/no
value of the value attribute.
If you post the schema that you currently have and have questions on what it should look like, you will get more specific schema feedback.
I'm guessing your question is if we can create a schema for your Example 3 - where you basically have an attribute called value and a element called value. This is possible
精彩评论