XSD1.1 validation

This should cover W3C XML Schema, Relax NG and DTD related problems.
gunjan10
Posts: 1
Joined: Thu Mar 15, 2018 9:44 am

XSD1.1 validation

Post by gunjan10 » Thu Mar 15, 2018 10:26 am

Hi,
I am new to XML and XSD validations

Below is my input xml

<ApplicationDetail>

<AppControlNumber>123</AppControlNumber>
<SourceCode>123</SourceCode>
<FormCode>254</FormCode>

</ApplicationDetail>

I need to validate this but the condition is as follows

------VALID CASES----
Condition1: If value in AppControlNumber tag is present then it should be valid

Condition2: If value in AppControlNumber tag & SourceCode is present then it should be valid

Condition3: If value in AppControlNumber tag & FormCode is present then it should be valid

Condition4: If value in AppControlNumber tag,SourceCode & FormCodeis present then it should be valid

Condition5: If value in SourceCode tag & FormCode is present then it should be valid

** i am not able to implement condition5
i have validated 4 conditions with xsd

<xs:schema attributeFormDefault="unqualified" elementFormDefault="qualified" xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="xml">
<xs:complexType>
<xs:sequence>
<xs:element name="ApplicationDetail">
<xs:complexType>
<xs:sequence>

<xs:element name="AppControlNumber" minOccurs="1" >
<xs:simpleType>
<xs:restriction base="xs:short"/>
</xs:simpleType>
</xs:element>

<xs:choice minOccurs="0" maxOccurs="unbounded">

<xs:element name="SourceCode" minOccurs="1">
<xs:simpleType>
<xs:restriction base='xs:string'>
</xs:restriction>
</xs:simpleType>
</xs:element>

<xs:element name="FormCode" minOccurs="1">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>

</xs:choice>

</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>

I tried XSD 1.1 to validate condition 5 but the solution isn't proper.Can someone help me preparing a schema which validates all the above rules.

Thanks
Gunjan

tavy
Posts: 179
Joined: Thu Jul 01, 2004 12:29 pm

Re: XSD1.1 validation

Post by tavy » Thu Mar 15, 2018 4:44 pm

Hello Gunjan,

A solution can be to make the AppControlNumber, SourceCode, FormCode elements optional (minOccurs="0") in a sequence, as in the example below. I don't know all the invalid/valid cases for you XML instance, so it is hard to create a schema. Also I suggest you to ask this questions on Stackoverflow or on the XML Schema mailing list (xmlschema-dev at w3 dot org), there are more experienced people there.

You can use also our Generate/Convert Schema tool to generate an XSD schema from an XML file, or from multiple XML files.

Code: Select all


<xs:sequence>
<xs:element name="AppControlNumber" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:short"/>
</xs:simpleType>
</xs:element>
<xs:element name="SourceCode" minOccurs="0">
<xs:simpleType>
<xs:restriction base='xs:string'>
</xs:restriction>
</xs:simpleType>
</xs:element>
<xs:element name="FormCode" minOccurs="0">
<xs:simpleType>
<xs:restriction base="xs:string">
<xs:minLength value="0" />
</xs:restriction>
</xs:simpleType>
</xs:element>
</xs:sequence>
Best Regards,
Octavian
Octavian Nadolu
<oXygen/> XML Editor
http://www.oxygenxml.com

Post Reply