mmarinov
asked on
Validate node in Xml file using XSD schema against value of attribute
Hello to all experts.
The problem that i have is related with this xml:
<RootNode>
<SubNode type="test1">
<AgainSubNode />
<AgainSubNode />
</SubNode>
<SubNode type="test2">
<AgainSubNode />
<AgainSubNode />
</SubNode>
I want to validate the xml using only xsd schema. The validation i have problem with is validating the xml file against the value of the attribute type. I have declared it as
<xs:simpleType name="Types">
<xs:restriction base="xs:string">
<xs:enumeration value="test1" />
<xs:enumeration value="test2" />
</xs:restriction>
</xs:simpleType>
</RootNode>
Is it possible to write something like this:
- if type = test1 then SubNode must have only one AgainSubNode node
- if type = test2 then subNode must have at least 3 AgainSubNode nodes
Thanks
The problem that i have is related with this xml:
<RootNode>
<SubNode type="test1">
<AgainSubNode />
<AgainSubNode />
</SubNode>
<SubNode type="test2">
<AgainSubNode />
<AgainSubNode />
</SubNode>
I want to validate the xml using only xsd schema. The validation i have problem with is validating the xml file against the value of the attribute type. I have declared it as
<xs:simpleType name="Types">
<xs:restriction base="xs:string">
<xs:enumeration value="test1" />
<xs:enumeration value="test2" />
</xs:restriction>
</xs:simpleType>
</RootNode>
Is it possible to write something like this:
- if type = test1 then SubNode must have only one AgainSubNode node
- if type = test2 then subNode must have at least 3 AgainSubNode nodes
Thanks
ASKER
Thanks Geert,
Do you have some links that i can see how xslt validation layer can be used.
Also is Schematron is dependent on the OS? I have requirement to use w3c schema and if I have to use something in addition it must be ok to run on windows, mac, linux
Regards
Martin
Do you have some links that i can see how xslt validation layer can be used.
Also is Schematron is dependent on the OS? I have requirement to use w3c schema and if I have to use something in addition it must be ok to run on windows, mac, linux
Regards
Martin
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you geert
I've got your point!
Martin
I've got your point!
Martin
welcome
You want the content type to be different depending on the value of an attribute
That is a so called "co-occurence constraint"
You cannot model that in W3C schema
For that you should use Schematron (www.schematron.com)
or add a validation layer using XSLT or something
cheers
Geert