I am trying to create a fairly simple XML schema for XML, similar to the following:
<messages> <item> <important_tag></important_tag> </item> <item> <important_tag></important_tag> <tag2></tag2> </item> <item> <tag2></tag2> <tag3></tag3> </item> </messages>
The idea is that <important_tag> will have a specific definition that may or may not appear in <item> . It can also appear more than once. In addition, there may be other tags before or after <important_tag> , which I cannot name in advance.
I would like to give a specific definition for <important_tag> . For example, define the attributes that should contain. I mean , if important_tag is present, it should match my definition. Any other tag must not conform to any definition.
I tried using the following scheme:
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"> <xs:element name="messages"> <xs:complexType> <xs:sequence> <xs:element ref="item" maxOccurs="unbounded"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="item"> <xs:complexType> <xs:sequence> <xs:element ref="important_tag" minOccurs="0"/> <xs:any minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> <xs:element name="important_tag"> <xs:complexType> <xs:simpleContent> ... specific definitions for important_tag ... </xs:simpleContent> </xs:complexType> </xs:element> </xs:schema>
This leads to an error saying that the scheme is ambiguous.
The exact error message is:
cos-nonambig: '<xs:element ref="important_tag">' makes the content model non-deterministic against '<xs:any>'. Possible causes: name equality, overlapping occurrence or substitution groups.
I am using Altova XML Spy.
How to solve this?
Thanks Dana
xml xsd ambiguity
Dana
source share