XML Schema force two attributes to be different

In my XML I have defined categories

<category id="3" parent-category-id="2">
    <name>Child category</name>
</category>

As you can see I have a category element, which can have a parent category defined. Both attributes are defined in my XML Schema file:

<xs:attribute name="id" use="required" type="xs:string" />
<xs:attribute name="parent-category-id" use="optional" type="xs:string" />

I also have keys and keyrefs set in my XSD file. Now I wonder if this is possible to somehow restrict parent-category-id, so that it cannot point to self id. For example I can write:

<category id="3" parent-category-id="3">

and such XML file will still validate, althought it shouldn't.

My keys and keyrefs are:

<xs:key name="ID">
    <xs:selector xpath="categories/category" />
    <xs:field xpath="@id" />
</xs:key>

<xs:keyref name="PARENT_CATEGORY_ID_REF" refer="ID">
    <xs:selector xpath="categories/category" />
    <xs:field xpath="@parent-category-id" />
</xs:keyref>

It would be great, if I could add some kind of restriction, that would tell the validator that id cannot == parent-category-id. Any ideas?

Answers


If you have an XSD validator that supports version 1.1, you can use an assert after the xs:attribute elements to enforce your restriction:

<xs:assert test="@id != @parent-category-id"/>

Personally I'm having trouble locating a validator that does support 1.1 though. Version 1.0 does not support assert.


Need Your Help

wxpython boxsizer addmany spacer

python wxpython boxsizer

How can I add a spacer between two items in a boxsizer, while using Add Many?

'Disabling' the MaxLength Property of a TextBox in C#

c# winforms

I'm currently working on a Windows Forms application and I need to have a TextBox which doesn't limit input size to Int32.MaxValue.

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.