放宽ng - 限制混合内容的总字符串长度(maxLength)

时间:2014-10-24 09:33:12

标签: xml xsd constraints relaxng

有没有办法限制混合内容元素的内容长度,还是有其他方法可以做到这一点?

我希望Relax ng架构要求"属性中的文本" element - 在我的示例XML中 - 仅限于一定数量的字符。

示例XML:

<attribute>
    , <tag>ART_QUANTITY</tag> single page etc. 
    Any number of characters is currently accepted here... 
    I would like to restrict this to the same number of characters 
    as in the source of this text, which is a database field.
</attribute>

我当前的Relax ng架构,并不关心长度。

<element name="attribute">
    <mixed>
        <!-- The text may contain references to other fields, which we indicate (surrond) with a tag -->
        <zeroOrMore>
            <element name="tag">
                <data type="NMTOKEN"/>
            </element>
        </zeroOrMore>
    </mixed>
</element>

2 个答案:

答案 0 :(得分:0)

我怀疑这在RELAX NG中是可行的。可能最简单的方法是序列化&#34;属性&#34;的内容。将元素转换为字符串,并使用您正在使用的编程语言检查其长度。 (参见例如Python lxml库)

答案 1 :(得分:0)

如果您的RNG处理器接受Schematron规则,请指定Schematron规则“string-length(string(。))&lt; 255”(或其他)。

如果您的RNG处理器不接受Schematron规则,但只接受纯RNG,我认为您运气不好。