Connecting Tech Pros Worldwide Help | Site Map

Schema - How to ensure that attributes are different?

  #1  
Old June 22nd, 2009, 10:57 AM
Newbie
 
Join Date: Jun 2009
Posts: 2
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!
  #2  
Old June 22nd, 2009, 04:28 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

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?
  #3  
Old June 23rd, 2009, 02:36 AM
Newbie
 
Join Date: Jun 2009
Posts: 2

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!
  #4  
Old June 23rd, 2009, 05:37 PM
Moderator
 
Join Date: Mar 2006
Posts: 1,103

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