2

What will be the xsd pattern for below xml having condition:

<?xml version="1.0" encoding="UTF-8"?>
<Tree>
    <fruits>
        <apple type="red">
        </apple>
         <apple type="red">
        </apple>
        <apple type="red">
        </apple>
    </fruits>
</Tree>

Validation requirement - validate xml only if type="green" occurs at least one time in xml. Above given xml should not pass validation as no element have type="green"

I have used below in my xsd.

 <xs:simpleType name="type">
    <xs:restriction base="xs:string">
      <xs:pattern value="[red|green]"/>
    </xs:restriction>
  </xs:simpleType>
  • Used following assertion to solve above problem But its giving error "http://www.w3.org/2001/XMLSchema :assert element is not present in context " – SnehalPatil May 29 '22 at 19:42

0 Answers0