Connecting Tech Pros Worldwide Forums | Help | Site Map

Schema - How to ensure that attributes are different?

Newbie
 
Join Date: Jun 2009
Posts: 2
#1: Jun 22 '09
Hi all,

I'm utterless clueless on how I can go about declaring in my schema that two attributes must contain different values, e.g.

Expand|Select|Wrap|Line Numbers
  1. <mail to="" from="">Text</mail>
How do I set the restriction in the schema that the "to" attribute and "from" attribute must contain different values? Hence 'to="Amy" from="Bob"' will validate, while 'to="Amy" from="Amy"' will fail the validation?

Hope to hear from this community soon. Thanks!

Moderator
 
Join Date: Mar 2006
Posts: 1,104
#2: Jun 22 '09

re: Schema - How to ensure that attributes are different?


Unfortunately, I do not know of any way to do this using just xml schema. Are you allowed to use other validation tools such as RelaxNG or SchemaTron?
Newbie
 
Join Date: Jun 2009
Posts: 2
#3: Jun 23 '09

re: Schema - How to ensure that attributes are different?


Sorry, I'm limited to using W3C - unless I break with the standard (in my project team, that is) and use a different schema type *plus* rebuild the schema for the rest of the XML.. Which is pretty long, so I'm hoping that there's a W3C-schema-solution somewhere out there!

Out of curiosity, how would I restrict the attribute values as mentioned in RelaxNG/SchemaTron? Thanks!
Moderator
 
Join Date: Mar 2006
Posts: 1,104
#4: Jun 23 '09

re: Schema - How to ensure that attributes are different?


Not quite an expert in schematron, but it'd be something like:
Expand|Select|Wrap|Line Numbers
  1. <pattern name="Unique atribute"> 
  2.   <rule context="mail"> 
  3.     <assert test="@to != @from">Sender and recipient are the same.</assert> 
  4.  
Reply