xmlvalidationdtddtd-parsing

How can I validate intermediate text via a DTD?


My XML-DTD failed to validate this code:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE init[
<!ELEMENT init(a)>
<!ELEMENT a(b,c,(d|e))>
<!ELEMENT b (#PCDATA)>
<!ELEMENT c (#PCDATA)>
<!ELEMENT d (#PCDATA)>
<!ELEMENT e (#PCDATA)>
]>
<init>
<a>
dolor
<b> Lorem </b>
dolor
<c> Ipsum </c>
<d> hi </d>
dolor
</a>
</init>

How can I validate the intermediate text via a DTD?

PD: Sorry, I edited the question -- my problem was not solved.

PD2: I use this for validation dtd-html: http://validator.w3.org/check


Solution

  • I see a couple of things:

    1. You need to add spaces between your element names and the content model (the left parenthesis).
    2. You need to declare a as a mixed content model.

    Example...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE init [
    <!ELEMENT init (a)>
    <!ELEMENT a (#PCDATA|b|c)*>
    <!ELEMENT b (#PCDATA)>
    <!ELEMENT c (#PCDATA)>
    ]>
    <init>
        <a>
            dolor
            <b> Lorem </b>
            dolor
            <c> Ipsum </c>
            dolor
        </a>
    </init>
    

    Example #2...

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE init [
    <!ELEMENT init (a)>
    <!ELEMENT a (#PCDATA|b|c|d|e)*>
    <!ELEMENT b (#PCDATA)>
    <!ELEMENT c (#PCDATA)>
    <!ELEMENT d (#PCDATA)>
    <!ELEMENT e (#PCDATA)>
    ]>
    <init>
        <a>
            dolor
            <b> Lorem </b>
            dolor
            <c> Ipsum </c>
            <d> hi </d>
            dolor
        </a>
    </init>