tenpn
tenpn

Reputation: 4716

Can I link maxOccurs in my schema to a value of another attribute in the target xml file?

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.

Upvotes: 0

Views: 173

Answers (2)

Nic Gibson
Nic Gibson

Reputation: 7143

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.

Upvotes: 1

Amber
Amber

Reputation: 526633

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

Upvotes: 1

Related Questions