Is there a way to specify that one of 2 attributes is required in XSD?
for example, I have a definition like this:
<xs:attribute name="Name" type="xs:string" use="optional" /> <xs:attribute name="Id" type="xs:string" use="optional" />
I want to be able to define that at least one of these is required. Is that possible?
Attributes are either optional or mandatory (by default they are optional). The "use" property in the XSD definition is used to specify if the attribute is optional or mandatory. To specify that an attribute must be present, use="required" (Note: use may also be set to "prohibited", but we'll come to that later).
The minOccurs attribute specifies the minimum number of times that the element can occur. It can have a value of 0 or any positive integer. The maxOccurs attribute specifies the maximum number of times that the element can occur.
An attribute provides extra information within an element. Attributes are defined within an XSD as follows, having name and type properties. An Attribute can appear 0 or 1 times within a given element in the XML document. Attributes are either optional or mandatory (by default the are optional).
Occurence Indicators minOccurs − Child element must occur minOccurs number of times.
No, I don't think you can do that with attributes. You could wrap two <xs:element>
into a <xs:choice>
- but for attributes, there's no equivalent construct, I'm afraid.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With