0

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

kjhughes
  • 106,133
  • 27
  • 181
  • 240
CodeNoob
  • 345
  • 4
  • 17

1 Answers1

1

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>
Daniel Haley
  • 51,389
  • 6
  • 69
  • 95
  • I change question , but you solution is good for case before. – CodeNoob Dec 01 '14 at 21:12
  • @CodeNoob - `a` is still a mixed content model and has to be declared a certain way. I added a second example. See http://www.w3.org/TR/xml11/#sec-mixed-content for more info. – Daniel Haley Dec 01 '14 at 22:14