J33nn
J33nn

Reputation: 3234

xmllint: Relax-NG validity error : Element tests has extra content

I'm trying to make xmllint to validate this schema. Unfortunately I came to some strange issue. It looks like xmllint interpretes wrong optional arguments without interleave tag included. Here is some test schema with misspelled tag person which should be signalized by xmllint. Unfortunately xmllint is raporting some other non-existing bug. Please take a look maybe I'm doing something wrong:

<?xml version="1.0" encoding="ISO-8859-1"?>
<grammar xmlns="http://relaxng.org/ns/structure/1.0">

<define name="testproject">
    <element name="testproject">
        <ref name="overview"/>
        <ref name="tests"/>
    </element>
</define>

<define name="overview">
    <element name="overview">
        <ref name="title"/>
        <oneOrMore>
            <ref name="person"/>
        </oneOrMore>
    </element>
</define>

<define name="tests">
    <element name="tests">

        <choice>
            <attribute name="file"/>

            <group>
                <ref name="title"/>
                <optional>
                    <ref name="field"/>
                </optional>
                <optional>
                    <ref name="field2"/>
                </optional>
                <optional>
                    <ref name="field3"/>
                </optional>

                <choice>
                    <zeroOrMore>
                        <ref name="test"/>
                    </zeroOrMore>
                    <zeroOrMore>
                        <ref name="tests"/>
                    </zeroOrMore>
                </choice>
            </group>
        </choice>
    </element>
</define>

<define name="test">
    <element name="test">
        <attribute name="name"/>

        <interleave>
            <optional>
                <ref name="title"/>
            </optional>
            <ref name="field"/>
            <zeroOrMore>
                <ref name="person"/>
            </zeroOrMore>
        </interleave>
    </element>
</define>

<define name="title">
    <element name="title">
        <text/>
    </element>
</define>

<define name="field">
    <element name="field">
        <text/>
    </element>
</define>

<define name="field2">
    <element name="field2">
        <text/>
    </element>
</define>

<define name="field3">
    <element name="field3">
        <text/>
    </element>
</define>

<define name="person">
    <element name="person">
        <text/>
    </element>
</define>

<start>
    <ref name="testproject"/>
</start>
</grammar>

And xml file content:

<?xml version="1.0" encoding="ISO-8859-1"?>

<testproject>
<overview>
    <title>
        some title
    </title>
    <person>J33nn</person>
</overview>

<tests>
    <title>
        Some title test
    </title>
    <field>as</field> 
    <test name="TestName">
        <title>Some title</title>

        <field>
            dasdasd
        </field>

        <peron>J33nn</peron>
    </test>
</tests>
</testproject>

And instead of reporting misspelled tag peron it reports something like this:

element field: Relax-NG validity error : Element tests has extra content: field

Upvotes: 1

Views: 2475

Answers (1)

Louis
Louis

Reputation: 151370

When I run xmllint on your XML file with your schema, I get the same error you report. However, note that the error is reported for <field>as</field>, which makes no sense whatsoever because this element should be acceptable in that position.

If I use jing to perform the validation, I get:

test.xml:23:16: error: element "peron" not allowed anywhere; expected the element end-tag or element "person"

which is a more sensible result. I'm certain that jing is right and xmllint is wrong.

Upvotes: 3

Related Questions