XML validation errors with XMLSchemaSet

jafardrone

New Member
I have a schema as follows:\[code\]<?xml version="1.0" encoding="utf-8"?><xs:schema id="MyDataSet" xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="http://stackoverflow.com/questions/12488209/urn:schemas-microsoft-com:xml-msdata"><xs:element name="Leaf" /> <xs:complexType name = "Leaf" mixed="true"> <xs:attribute name="ID" type="xs:string" /> </xs:complexType> <xs:element name="Frame" /> <xs:complexType name="Frame" mixed="true"> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="Leaf" type ="Leaf" nillable="true"/> <xs:element minOccurs="0" maxOccurs="unbounded" name="Frame" type="Frame" nillable="true"/> </xs:sequence> <xs:attribute name="ID" type="xs:string" /> </xs:complexType> <xs:element name="Document"> <xs:complexType> <xs:sequence> <xs:element minOccurs="1" maxOccurs="1" name="Version" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="1" name="MetaData1" type="xs:string" /> <xs:element minOccurs="0" maxOccurs="1" name="MetaData2" type="xs:string" /> <xs:element minOccurs="1" maxOccurs="unbounded" name="Page" nillable="false"> <xs:complexType mixed="true"> <xs:sequence> <xs:element minOccurs="0" maxOccurs="unbounded" name="Frame" type="Frame" /> </xs:sequence> </xs:complexType> </xs:element> </xs:sequence> </xs:complexType> </xs:element></xs:schema>\[/code\]Basically its a recursive structure. A document can have a list of pages. It must contain atleast 1 page. A Page consists of list of frames. A Frame can have sub-frames or leaf (i.e cannot contain subframes). MetaData1 and MetaData2 are optional and can occur anywhere.A sample XML would be as follows:\[code\]<?xml version="1.0" encoding="UTF-8"?><Document> <Version>1.1</Version> <MetaData1>Somemetadata</MetaData1> <Page>Page1 <Frame ID="1">Frame1 <Frame ID="2">SubFrame1 <Frame ID="3">SubFrame2 <Leaf ID="1">Alone</Leaf> </Frame> <Leaf ID="2">Alone2</Leaf> </Frame> </Frame> <Frame ID="3">SubFrame3 </Frame> </Page> <MetaData2 /></Document>\[/code\]I am using XmlReaderSettings and XmlSchemaSet to do the XML validation against the schema. For some reason I am getting these 2 errors:1) {"The element 'Document' has invalid child element 'Metadata2'. List of possible elements expected: 'Page'."}I think its because it is reading in sequence whereas in my case those elements can appear in any order. I tried doing the xs:all attribute but it doesn't work with maxoccurs=unbounded. Any other way ?2) {"The element 'Frame' has invalid child element 'Leaf'. List of possible elements expected: 'Frame'."}Could this be same as (1) ? The error occurs for Leaf ID=2Any help would be appreciated. Thanks
 
Back
Top