XSD with "required" attribute option related query
XSD with "required" attribute option related query
(OP)
Hello All,
I am new to XSD and XML and need to explore if there is option to make sure that any one attribute in a set of attributes within same element is required.
Example:
<xs:element name="where" maxOccurs="1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="condition" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="alias1" use="required"/>
<xs:attribute type="xs:string" name="col1" use="required"/>
<xs:attribute type="xs:string" name="operator" use="required"/>
<xs:attribute type="xs:string" name="string" use="optional"/>
<xs:attribute type="xs:string" name="number" use="optional"/>
<xs:attribute type="xs:string" name="date" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Here I want to ensure that minimum one attribute in a set of 3 attributes (mentioned as optional in above) are required. All can not be optional , however any one (can be more than one also) is required.
Thanks,
Rajneesh
I am new to XSD and XML and need to explore if there is option to make sure that any one attribute in a set of attributes within same element is required.
Example:
<xs:element name="where" maxOccurs="1" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="condition" maxOccurs="unbounded" minOccurs="1">
<xs:complexType>
<xs:simpleContent>
<xs:extension base="xs:string">
<xs:attribute type="xs:string" name="alias1" use="required"/>
<xs:attribute type="xs:string" name="col1" use="required"/>
<xs:attribute type="xs:string" name="operator" use="required"/>
<xs:attribute type="xs:string" name="string" use="optional"/>
<xs:attribute type="xs:string" name="number" use="optional"/>
<xs:attribute type="xs:string" name="date" use="optional"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
Here I want to ensure that minimum one attribute in a set of 3 attributes (mentioned as optional in above) are required. All can not be optional , however any one (can be more than one also) is required.
Thanks,
Rajneesh
RE: XSD with "required" attribute option related query
With what version of XML Schema are you working?
RE: XSD with "required" attribute option related query
Thanks for your reply.
version="1.0"
This XSD is generated through online tool , by providing XML as input file. XML is also 1.0 version.
Thanks,
Rajneesh
RE: XSD with "required" attribute option related query
But even if the online tool you're using does not support version 1.1, and as long as your validator/parser does, you can post-process the schema to mandate the presence of one of the attributes.
The highlighted areas of the schema require your attention. Basically, you say version 1.1 is required and then include an assertion that returns true when one of the optional attributes is included in the document.
CODE --> XML
An invalid XML document:
CODE --> XML
A valid XML document (at least one of the attributes is present):
CODE --> XML
RE: XSD with "required" attribute option related query
RE: XSD with "required" attribute option related query
I am working inside the database, it won't be possible.
Oracle XML DB only supports XML Schema 1.0.
Thanks,
Rajneesh
RE: XSD with "required" attribute option related query
Then you can't use assertions to extend the validation of your schemas.
I'm not familiar with your environment, but can't you submit your XML documents to an XSLT? A transformation stylesheet can be used as a validator, also.