views:

40

answers:

2

I'm defining an xml schema for a file that looks something like this:

<data>
    <config><segmentcount value="10"/></config>
    <foos>
        <foo>
            <segments>
                <segment data="X"/>
                <segment data="X"/>
                <segment data="X"/>
                <segment data="X"/>
                <segment data="X"/>
            </segments>
        </foo>
        <foo>
            <segments>
                ...

I've already made a schema for the general structure. However I want to enforce that the number of segment elements in segments is always the same as the value attribute of segmentcount. In the maxOccurs attribute of segments, I tried the xpath /aitt:data/aitt:config/aitt:segmentcount[1]@value, but the parser told me than maxOccurs has to be a non-negative int or unbounded.

Is there a trick to do this?

Cheers in advance.

+1  A: 

I don't believe there's a way to link the schema and the data in the fashion you're desiring.

Amber
+1  A: 

There isn't (as far as I know) a way to do this with XSD. You probably need to consider using Schematron rules to achieve this sort of validation. I've had success with storing Schematron rules in annotation elements of my schemas.

Nic Gibson
Both the two answers so far are correct, but I'm going to tick this one for the schematron link. Thanks for the info, guys.
tenpn