XSD related quetion to enforce "required" option
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 4
- Joined: Fri Feb 21, 2020 1:51 pm
XSD related quetion to enforce "required" option
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
-
- Posts: 388
- Joined: Thu Jul 01, 2004 12:29 pm
Re: XSD related quetion to enforce "required" option
Hello Rajneesh,
I think that you can add this constraint only using XSD 1.1 "xs:assert" or "xs:alternative", or maybe using a Schematron schema and create an assert there.
You can read more about XSD 1.1 in the specification: https://www.w3.org/TR/xmlschema11-1/
Maybe you can address this question on the XML Schema list: xmlschema-dev@w3.org
Best Regards,
Octavian
I think that you can add this constraint only using XSD 1.1 "xs:assert" or "xs:alternative", or maybe using a Schematron schema and create an assert there.
You can read more about XSD 1.1 in the specification: https://www.w3.org/TR/xmlschema11-1/
Maybe you can address this question on the XML Schema list: xmlschema-dev@w3.org
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
-
- Posts: 4
- Joined: Fri Feb 21, 2020 1:51 pm
Re: XSD related quetion to enforce "required" option
Thanks Tavy,
I reached to w3.org and below is recommendation from their end:
I think that, the issue you've mentioned can be solved using an XSD 1.1 <assert> instruction. I guess that, you can rewrite your XSD fragment to following (I've only added an <assert>), to achieve what you've mentioned,
<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:assert test="exists(@string | @number | @date)"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
However I am working inside the database, it won't be possible.
Oracle XML DB only supports XML Schema 1.0.
Thanks,
Rajneesh
I reached to w3.org and below is recommendation from their end:
I think that, the issue you've mentioned can be solved using an XSD 1.1 <assert> instruction. I guess that, you can rewrite your XSD fragment to following (I've only added an <assert>), to achieve what you've mentioned,
<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:assert test="exists(@string | @number | @date)"/>
</xs:extension>
</xs:simpleContent>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
However I am working inside the database, it won't be possible.
Oracle XML DB only supports XML Schema 1.0.

Thanks,
Rajneesh
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service