Jump to content
Sign in to follow this  
dornad

Restriction on a Set of Elements

Recommended Posts

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 :

  1. A main page must exist always
  2. 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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...