Re: Dependencies between attributes and elements

I'm struggling with a similar issue. As I understand it, you can't do it 
with a custom attribute, but you can use xsi:type provided you 
(manually) define all the types you want to support in your schema.

<vector xsi:type="intvector"> <!-- and in schema define complextypes intvector, stringvector, numbervector, ... and even intpair, inttriple, ... -->
  <value>2</value> <!-- if not int throws a error -->
</vector>

But it has drawbacks: you have to define all of the types and you have 
to change the XML to use xsi:type instead of your own attribute.

Kind regards,

Andy Den Tandt




Joćo Cruz Morais wrote:
> Thanks for your answer Michael, I think I'll deal with the document
> structure with XSD and do the remaining validation in my java app.
> One more thing though:
>
> Right now I'm using an element called int-vector to specify a list of
> int values. Is it possible to make that element go away and replace it
> for a generic one, with an attribute specifying the vector type? In
> other words is it possible to establish a relationship between the
> value of an element attribute and his children?
> Example:
>
> <vector type="int">
>   <value>2</value> <!-- if not int throws a error -->
> </vector>
>
> Thanks a lot,
> Joćo
>
> On 06/08/07, Michael Kay <mike@saxonica.com> wrote:
>   
>>> Given this simple xml:
>>>
>>> <vector size="2">
>>>   <value>1</value>
>>>   <value>3</value>
>>> </vector>
>>>
>>> Is there a way to validate the number of <value> elements
>>> according to the vector size attribute?
>>> I'm tempted to say no, so should I make this kind of
>>> validation inside my program?
>>>       
>> XML Schema 1.1 will add this capability using assertions:
>>
>> <xs:assert test="count(value) = @size"/>
>>
>> Meanwhile you have to resort to other approaches, e.g. your own validation
>> code in XSLT, or Schematron.
>>
>> Michael Kay
>> http://www.saxonica.com/
>>
>>
>>     
>
>
>   

Received on Tuesday, 7 August 2007 10:46:40 UTC