Reputation: 12375
I have this XSD element defined:
<xsd:element name="CU_FIRST_NAME">
<xsd:annotation>
<xsd:documentation>
The first name of the customer that is getting billed for the order
</xsd:documentation>
</xsd:annotation>
<xsd:simpleType>
<xsd:restriction base="xsd:string">
<xsd:maxLength value="50"/>
</xsd:restriction>
</xsd:simpleType>
</xsd:element>
I know this could be replaced by a single element, but I have a more complex element (a sequence) that I need to make optional.
Is there a way to make a first-child (i.e. just below <xsd:schema>
in the hierarchy) element optional?
To be clear, I'd like to make the entire CU_FIRST_NAME
node, along with all of its children, optional.
Upvotes: 0
Views: 2527
Reputation: 12375
I ended up realizing that the element I was using was actually a ref within a higher level object.
The way I solved this was thus:
Original code:
<xsd:element ref="CU_FIRST_NAME"/>
New code:
<xsd:element ref="CU_FIRST_NAME" minOccurs="0"/>
So, really I was asking the wrong question.
Upvotes: 1
Reputation: 3221
<xs:element name="item" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="title" type="xs:string"/>
<xs:element name="note" type="xs:string" minOccurs="0"/>
<xs:element name="quantity" type="xs:positiveInteger"/>
<xs:element name="price" type="xs:decimal"/>
</xs:sequence>
</xs:complexType>
</xs:element>
use minOccurs="0"
in the very first element. this will make it so that if you select the top you have to select the rest. but if you put that in the children as well then they will all be optional.
Upvotes: 0