guillem
guillem

Reputation: 115

Trying to validate XML against DTD

I'm trying to produce a valid xdxf document (here's the DTD). I've managed to sort out all errors except one, and I can't figure what's wrong.

The relevant part is

...
<def>
    <def>
        <gr>n. s.</gr>
        <deftext>
            <tr>pronunciation</tr>
            <dtrn>Meaning</dtrn>
        </deftext>
        <co>Inflected forms</co>
        <ex>
            <ex_orig>Examples</ex_orig>
        </ex>
    </def>
    <def>
        <gr>n. s.</gr>
        <deftext>
            <tr>pronunciation</tr>
            <dtrn>Another meaning</dtrn>
        </deftext>
        <co>Inflected forms</co>
        <ex>
            <ex_orig>Examples</ex_orig>
        </ex>
    </def>
</def>
...

The error I got (twice, so I guess it's for the inner def, not the outer) is:

The content of element type "def" must match "(gr?,ex*,co*,sr?,etm?,categ*,(def+|deftext))".

That's none or one gr (ok), none or many ex (ok), none or many co (ok), none or one sr, etm (none), none or many categ (ok) and either one or more def or exactly one deftext (ok for both outer and inner def). I'm I understanding this right or is there something I'm overlooking?

Upvotes: 1

Views: 65

Answers (1)

potame
potame

Reputation: 7905

Yes, you're right when you say:

That's none or one gr (ok), none or many ex (ok), none or many co (ok), none or one sr, etm (none), none or many categ (ok) and either one or more def or exactly one deftext (ok for both outer and inner def). I'm I understanding this right or is there something I'm overlooking?

But each time you write a comma, it means "then" - the order must be respected.

Thus your document is incorrect in respect to this DTD because in the following:

<def>
    <gr>n. s.</gr>
    <deftext>
        <tr>pronunciation</tr>
        <dtrn>Another meaning</dtrn>
    </deftext>
    <co>Inflected forms</co>
    <ex>
        <ex_orig>Examples</ex_orig>
    </ex>
</def>

the element <co> and <ex> are not allowed to appear after <deftext>.

A corrected version would be:

<def>
    <gr>n. s.</gr>
    <ex>
        <ex_orig>Examples</ex_orig>
    </ex>
    <co>Inflected forms</co>
    <deftext>
        <tr>pronunciation</tr>
        <dtrn>Another meaning</dtrn>
    </deftext>
</def>

With the <gr> first, then <ex>, then <co> and <deftext> at the end.

Upvotes: 2

Related Questions