dornad Posted July 19, 2007 Share Posted July 19, 2007 Hello everyone,I'm new at the XML Schema scene and I was wondering if someone can give me a hand with the following:I have the following structure in a xml: <pages> <page id="1" url="index.html" type="main"> <page id="2" url="index1.html" type="internal"> <page id="3" url="index2.html" type="catalog"> <page id="4" url="index3.html" type="product"> ....</pages> I already have the xsd with that structure and it works fine. However I need to define a set of restrictions over the elements (pages). Here is an example of some of the restrictions : A main page must exist always A product page can only exist if there is a catalog page. I imagine that the others are deducible once I find out how to do the ones mentioned.Thanks Link to comment Share on other sites More sharing options...
boen_robot Posted July 19, 2007 Share Posted July 19, 2007 I'm sorry, but XML Schema 1.0 does not allow the existence or value of one node to determine the existence or value of another node. At least not directly. I remember reading something about abstract types here on this forum, but this required a modification in the XML file itself to include a special attribute at the element containing abstract types... or something like that... anyway, the point stands.The only thing you could do is a complete rewrite of your XML and schema into a structure that would allow that. For example: <pages> <main id="1" url="index.html"/> <internal id="2" url="index1.html"/> <catalog id="3" url="index2.html"> <product id="4" url="index3.html"/> </catalog></pages> With that structure, you can define a minOccurance of 1 to <main/> and define <product/> as allowed in <catalog/>. With no <catalog/>, there can't be any <product/> to place inside it.XML Schema 1.1 is aimed at fixing this while still being backwards compatible, but it's still not a recommendation and as such, it's not yet supported by any validator. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.