I have an xml element A which based on his value I want to do couple thing:
If A=1 I want to make element B optional element.
If A=2 I want to make element B required and his values to be one of 3,4 or 5. and etc.
This is my new xsd :
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:sch="http://www.ascc.net/xml/schematron" elementFormDefault="qualified" > <xs:element name="books"> <xs:complexType> <xs:sequence> <xs:element name="book" type="bookType" maxOccurs="unbounded"> <xs:annotation> <xs:appinfo> <sch:pattern id="onLoanTests" xmlns:sch="http://purl.oclc.org/dsdl/schematron"> <sch:rule context="book"> <sch:report test="@on-loan and not(@return-date)"> Every book that is on loan must have a return date </sch:report> </sch:rule> </sch:pattern> </xs:appinfo> </xs:annotation> </xs:element> </xs:sequence> </xs:complexType> </xs:element> <xs:complexType name="bookType"> <xs:sequence> <xs:element name="title" type="xs:string" /> <xs:element name="author" type="xs:string" /> <xs:element name="publication-date" type="xs:string" /> </xs:sequence> <xs:attribute name="publisher" type="xs:string" use="required" /> <xs:attribute name="on-loan" type="xs:string" use="required" /> <xs:attribute name="return-date" type="xs:string" use="optional" /> </xs:complexType> </xs:schema>
I tried to write a little example which suppose to fail like this :
<books> <book publisher="ddd" on-loan="sdsd"> <title> idan title </title> <author> idan author </author> <publication-date> idan date </publication-date> </book> </books>
Now, using the xml I provided I don't get validation error. I assumed I will get the message "Every book that is on loan must have a return date" And that the xml won't be valid. Suggestions as to why ?
Thanks


Sign In
Create Account

Back to top









