Reputation: 17538
This is probably basic but I am struggling to implement it with my basic knowledge of XML and XML Schema.
Any help is gratefully received.
Given the following XML file snippet:
<record>
...
<update_type>3</update_type>
<reason>User entered in error</reason>
...
</record>
<record>
...
<update_type>1</update_type>
<reason></reason>
...
</record>
Is there a way I can conditionally validate the XML file ensuring the <reason>
string element is mandatory when the <update_type>
numeric element has a value of 3 but optional when the <update_type>
is another value?
Thanks in advance...
Upvotes: 3
Views: 2308
Reputation: 4900
No you can't, not with XML Schema.
You need to write that logic in your code, after you validate the XML structure with the Schema and make sure it's content is valid.
Upvotes: 4