XSD validation with minOccurs="1"
This should cover W3C XML Schema, Relax NG and DTD related problems.
-
- Posts: 2
- Joined: Tue May 04, 2010 6:43 pm
XSD validation with minOccurs="1"
I have a problem validating an XML document against its XSD. Specifically, I have set minOccurs="1" for an element in the XSD. The element does not exist in the XML file. The XML file validates against the XSD without errors! How can this happen? Example code:
XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="c1">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="candidate" minOccurs="1" maxOccurs="1">
...
</xs:element>
<xs:element name="party" minOccurs="1" maxOccurs="1">
...
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML:
<c1>
<candidate ...>
</c1>
Note that there is no party element in the XML, and that it has minOccurs="1" in the XSD. The XML file validates without errors against the XSD, both in oXygen and in my C# validation against the same XSD.
What am I doing wrong? Doesn't minOccurs="1" mean that an element MUST exist at least one time in the XML file?
XSD:
<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="c1">
<xs:complexType>
<xs:sequence>
<xs:choice maxOccurs="unbounded">
<xs:element name="candidate" minOccurs="1" maxOccurs="1">
...
</xs:element>
<xs:element name="party" minOccurs="1" maxOccurs="1">
...
</xs:element>
</xs:choice>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
XML:
<c1>
<candidate ...>
</c1>
Note that there is no party element in the XML, and that it has minOccurs="1" in the XSD. The XML file validates without errors against the XSD, both in oXygen and in my C# validation against the same XSD.
What am I doing wrong? Doesn't minOccurs="1" mean that an element MUST exist at least one time in the XML file?
-
- Posts: 9421
- Joined: Fri Jul 09, 2004 5:18 pm
Re: XSD validation with minOccurs="1"
Hi,
You have a choice which contains both candidate and party.
An <xs:choice> allows only one of the contained elements to be present within the containing element. So if candidate appears, there is no party. If you would choose party, then the constraints for it would be used.
Regards,
Radu
You have a choice which contains both candidate and party.
An <xs:choice> allows only one of the contained elements to be present within the containing element. So if candidate appears, there is no party. If you would choose party, then the constraints for it would be used.
Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
<oXygen/> XML Editor
http://www.oxygenxml.com
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