XSD: Single optional element in sequence

omemo

New Member
I have XML files of the form:\[code\]<?xml version="1.0" encoding="ISO-8859-1" standalone="yes"?><hw:config name="test" xmlns:hw="hw"> <switch var="var.test" > <case vhttp://stackoverflow.com/questions/11341386/alue="a"> </case> <case value="http://stackoverflow.com/questions/11341386/b"> </case> <default> </default> <case value="http://stackoverflow.com/questions/11341386/c"> </case> </switch></hw:config>\[/code\]I want an XSD that allows that there may be one default block or not, but not more than one. It may appear at any position between the case blocks.The following XSD should do the job, but xmllint (libxml2) says 'The content model is not determinist.':\[code\]<?xml version="1.0"?><xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:hw="hw" targetNamespace="hw" > <xsd:simpleType name="defaultType"> <xsd:restriction base="xsd:string"> </xsd:restriction> </xsd:simpleType> <xsd:complexType name="caseType"> <xsd:simpleContent> <xsd:extension base="xsd:string"> <xsd:attribute name="value" type="xsd:string" use="required" /> </xsd:extension> </xsd:simpleContent> </xsd:complexType > <xsd:complexType name="switchType" > <xsd:sequence> <xsd:element name="case" minOccurs="0" maxOccurs="unbounded" type="hw:caseType" /> <xsd:sequence minOccurs="0" maxOccurs="1"> <xsd:element name="default" type="hw:defaultType" /> <xsd:element name="case" minOccurs="0" maxOccurs="unbounded" type="hw:caseType" /> </xsd:sequence> </xsd:sequence> <xsd:attribute name="var" type="xsd:string" use="required" /> </xsd:complexType> <xsd:complexType name="configType" > <xsd:sequence> <xsd:element name="switch" type="hw:switchType" /> </xsd:sequence> <xsd:attribute name="name" type="xsd:string" /> </xsd:complexType> <xsd:element name="config" type="hw:configType" /></xsd:schema>\[/code\]Why is this Schema not-determinist? Is there any way to rephrase this so that it becomes determinist?
 
Back
Top