Optional AttributeGroup
I have to define a attribute grou开发者_Go百科p for 2 mutually inclusive data elements. In the below example if TO_DT
is present FROM_DT
has to be present and TO_DT
is not present then FROM_DT
is not present.
I thought of creating these as mandatory attributes and define attributegroup as optional but its not working:
<xs:attributeGroup name="DateRangeAttributes" id="Element_Common_545">
<xs:attribute name="TO_DT" type="xs:date" use="required" id="Element_Common_547"/>
<xs:attribute name="FROM_DT" type="xs:date" use="required" id="Element_Common_546"/>
<xs:attributeGroup>
Can anyone suggest a way to handle this using attributes
Sorry, that kind of constraint can't be enforced by XML Schema (1.0). You'll have a enforce it elsewhere (such as with code or XSLT) or change the format. Possibilities:
- Provide default values so both are effectively always present.
- Use a single attribute containing a length-2 list of dates.
- Use elements (you could also control the order, unlike attributes).
These constraints can be expressed in Schematron and in XML Schema 1.1.
精彩评论