开发者

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 val开发者_JS百科ue="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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜