Why would WMHelp XMLPad fail to validate 3, 5, 7 elements for an XSD that constraints element cardinality via minOccurs="2"
and maxOccurs="unbounded"
?
I have this simple XML:
<?xml version="1.0" encoding="UTF-8"?>
<root xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="mySchema.xsd">
<items>
<item id="1">
<levels>
<level>one</level>
</levels>
</item>
<item id="2">
<levels>
<level>one</level>
<level>two</level>
</levels>
</item>
<item id="3">
<levels>
<level>one</level>
<level>two</level>
<level>three</level>
</levels>
</item>
<item id="4">
<levels>
<level>one</level>
<level>two</level>
<level>three</level>
<level>four</level>
</levels>
</item>
<item id="5">
<levels>
<level>one</level>
<level>two</level>
<level>three</level>
<level>four</level>
<level>five</level>
</levels>
</item>
</items>
</root>
I want each <levels>
list to contain at least 2 <level>
elements. So here is the XSD I wrote:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:complexType name="ItemType">
<xs:sequence>
<xs:element name="levels">
<xs:complexType>
<xs:sequence>
<xs:element name="level" type="xs:string" minOccurs="2" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
<xs:attribute name="id" type="xs:string"/>
</xs:complexType>
<xs:element name="root">
<xs:complexType>
<xs:all>
<xs:element name="items" minOccurs="0">
<xs:complexType>
<xs:sequence>
<xs:element name="item" type="ItemType" minOccurs="1" maxOccurs="unbounded"/>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:all>
</xs:complexType>
</xs:element>
</xs:schema>
When I validate my XML against my XSD in a tool called "WMHelp XMLPad", I get a warning for <item id="1">
, but also - unexpectedly! - for <item id="3">
and <item id="5">
. It looks like even counts of <item>
(2, 4) are OK, but odd ones (1, 3, 5) are rejected.
Element levels {} has invalid structure for schema definition: (level{2..unbounded})
What might I be doing wrong?
That's an odd problem.
Neither I nor my Xerces-based XSD validator see anything wrong with your expectation: Only the number of <item id="1">
level
elements violates the XSD:
[Error] try.xml:7:16: cvc-complex-type.2.4.i
: The content of element 'levels' is not complete. 'level' is expected to occur a minimum of '2' times. One more instance is required to satisfy this constraint.
There are no other validation errors.
This appears to be a bug in WMHelp XMLPad
.
Follow-up: The original domain (www.wmhelp.com
, per this 2006 announcement) for WMHelp XMLPad
is redirecting to sketchy sites, so it's unclear how one would report a bug.
Conclusion: WMHelp XMLPad
is unreliable, unsupported, and should be avoided.