Note that there are some explanatory texts on larger screens.

plurals
  1. POIgnore parent element in XML schema
    primarykey
    data
    text
    <p>I have an xml file that looks like this:</p> <pre><code>&lt;RootItem&gt; &lt;Items&gt; &lt;Item /&gt; &lt;Item /&gt; &lt;Item /&gt; &lt;/Items&gt; &lt;Values&gt; &lt;Value /&gt; &lt;Value /&gt; &lt;Value /&gt; &lt;/Values&gt; &lt;AnotherItem /&gt; &lt;/RootItem&gt; </code></pre> <p>I'm using Trang to translate this into a .xsd schema, and using xjc to translate the schema into annotated Java classes (that work smoothly with jaxB to marshal and unmarshall my documents) My only problem is that xjc gives me these classes:</p> <ul> <li>RootItem.java</li> <li>Items.java</li> <li>Item.java</li> <li>Values.java</li> <li>Value.java</li> <li>ObjectFactory.java (required by JaxB)</li> </ul> <p>I don't want a "Items" or a "Values" class. How do I format my schema to tell it to ignore the parent element and just make a "List items" object in my RootItem class?</p> <p>What I want:</p> <ul> <li>RootItem.java</li> <li>Item.java</li> <li>Value.java</li> <li>ObjectFactory.java (required by JaxB)</li> </ul> <p>Thanks!</p> <p>Edit: Here's the schema generated by Trang:</p> <pre><code>&lt;xs:element name="RootItem"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element ref="Items"/&gt; &lt;xs:element ref="Values"/&gt; &lt;/xs:sequence&gt; &lt;xs:element name="AnotherItem" use="required" type="xs:NCName"/&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="Items"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element maxOccurs="unbounded" ref="Item"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; &lt;xs:element name="Values"&gt; &lt;xs:complexType&gt; &lt;xs:sequence&gt; &lt;xs:element maxOccurs="unbounded" ref="Value"/&gt; &lt;/xs:sequence&gt; &lt;/xs:complexType&gt; &lt;/xs:element&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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