Note that there are some explanatory texts on larger screens.

plurals
  1. POIs this XML example possible to write a schema for?
    text
    copied!<p>I have two XML examples that I want to write a schema for:</p> <p>Example 1: </p> <p><code>&lt;attributes&gt;</code><br> <code>&lt;attribute type="test" value="yes"/&gt;</code><br> <code>&lt;/attributes&gt;</code></p> <p>Example 2:</p> <p><code>&lt;attributes&gt;</code><br> <code>&lt;attribute type="test"&gt;</code><br> <code>&lt;value x="100" y="50"&gt;yes&lt;/value&gt;</code><br> <code>&lt;/attribute&gt;</code><br> <code>&lt;/attributes&gt;</code></p> <p>Example 3:</p> <p><code>&lt;attributes&gt;</code><br> <code>&lt;attribute type="test" value="no"&gt;</code><br> <code>&lt;value x="100" y="50"&gt;yes&lt;/value&gt;</code><br> <code>&lt;/attribute&gt;</code><br> <code>&lt;/attributes&gt;</code></p> <p>Is it possible to have a schema that works for these? With 'value' being an attribute in one and an element in the other?</p> <p><strong>Update</strong> Right, I think I understand my problem now.</p> <p>I have this XSD:</p> <pre><code>&lt;xs:complexType name="Attribute"&gt; &lt;xs:sequence &gt; &lt;xs:element name="value" type="Value" minOccurs="0" maxOccurs="unbounded"&gt; &lt;/xs:element&gt; &lt;/xs:sequence&gt; &lt;xs:attribute name="type" type="xs:string" use="required"&gt; &lt;/xs:attribute&gt; &lt;xs:attribute name="value" type="xs:string" &gt; &lt;/xs:attribute&gt; &lt;/xs:complexType&gt; </code></pre> <p>But when I try to use JAXB to generate java classes from the XSD I get an error:</p> <pre><code> [xjc] [ERROR] Property "Value" is already defined. Use &amp;lt;jaxb:property&gt; 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 </code></pre> <p>I guess this is a limitation in JAXB rather than the XSD. It will try to create two methods called getValue() which will fail. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload