Note that there are some explanatory texts on larger screens.

plurals
  1. POAssistance with XML XSD choice between multiple elements
    primarykey
    data
    text
    <p>I have an XML document as so:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;Data&gt; &lt;AddressStreetNumber&gt;123&lt;/AddressStreetNumber&gt; &lt;AddressStreetName&gt;Main St&lt;/AddressStreetName&gt; &lt;AddressUnitNumber&gt;10-B&lt;/AddressUnitNumber&gt; &lt;AddressUnitType&gt;Apt&lt;/AddressUnitType&gt; &lt;AddressLine1&gt;123 Main St Apt 10-B&lt;/AddressLine1&gt; &lt;/Data&gt; </code></pre> <p>I want the definition in the XSD to document that the first 4 elements are to be included OR the last element is to be included. Basically the consumer can opt to split the address out or just use the element "addressline1" to put the entire address1 information. How do I describe this in an XSD? I've tried using xsd:group and xsd:choice but it doesnt seem to work (or validate). </p> <p>Example:</p> <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt; &lt;xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema"&gt; &lt;xs:group name="householdaddress1parts"&gt; &lt;xs:all&gt; &lt;xs:element name="AddressStreetNumber" type="xs:unsignedInt" minOccurs="0" /&gt; &lt;xs:element name="AddressStreetName" minOccurs="0" &gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:minLength value="1"/&gt; &lt;xs:maxLength value="100"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:element&gt; &lt;xs:element name="AddressUnitNumber" minOccurs="0"&gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:minLength value="1"/&gt; &lt;xs:maxLength value="16"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:element&gt; &lt;xs:element name="AddressUnitType" minOccurs="0"&gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:minLength value="1"/&gt; &lt;xs:maxLength value="16"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:element&gt; &lt;/xs:all&gt; &lt;/xs:group&gt; &lt;xs:group name="householdaddress1"&gt; &lt;xs:all&gt; &lt;xs:element name="AddressLine1" minOccurs="0" &gt; &lt;xs:simpleType&gt; &lt;xs:restriction base="xs:string"&gt; &lt;xs:minLength value="1"/&gt; &lt;xs:maxLength value="164"/&gt; &lt;/xs:restriction&gt; &lt;/xs:simpleType&gt; &lt;/xs:element&gt; &lt;/xs:all&gt; &lt;/xs:group&gt; &lt;xs:choice minOccurs="0"&gt; &lt;xs:group ref="householdaddress1parts"&gt;&lt;/xs:group&gt; &lt;xs:group ref="householdaddress1"&gt;&lt;/xs:group&gt; &lt;/xs:choice&gt; &lt;/xs:schema&gt; </code></pre> <p>I've tried a few other variations but I'm guessing I'm totally off track here even after reading documentation for a while (or it could be something totally obvious). This is my first foray into XSD and I'm sure it shows. Any help with this is appreciated.</p>
    singulars
    1. This table or related slice is empty.
    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.
    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