问题
I'm working on a XML file and I'm having issues with it.
Here's the DTD :
<!ELEMENT book (bookinfo,chapter*)>
<!ELEMENT chapter (title,section*)>
<!ELEMENT title (#PCDATA)>
<!ELEMENT bookinfo (title,author,copyright)>
<!ELEMENT author (firstname,surname)>
<!ELEMENT copyright (year,holder)>
<!ENTITY % divers "para|programlisting|itemizedlist|orderedlist">
<!ELEMENT section (title,(%divers;)+)>
<!ELEMENT para (#PCDATA)>
<!ELEMENT programlisting (#PCDATA)>
<!ELEMENT holder (#PCDATA)>
<!ELEMENT surname (#PCDATA)>
<!ELEMENT firstname (#PCDATA)>
<!ELEMENT year (#PCDATA)>
<!ELEMENT itemizedlist (listitem+)>
<!ELEMENT orderedlist (listitem+)>
<!ELEMENT listitem (%divers;)+>
Here's what I've done so far (Validation is okay with this part)
<?xml version="1.0" encoding='ISO-8859-1' standalone="no"?>
<!DOCTYPE book SYSTEM "simpledocbook.dtd">
<?xml-stylesheet href="docbook.xml" type="application/xml"?>
<book>
<bookinfo>
<title></title>
<author>
<firstname></firstname>
<surname></surname>
</author>
<copyright>
<year></year>
<holder></holder>
</copyright>
</bookinfo>
<chapter>
<title></title>
<section>
<title></title>
<para></para>
<programlisting></programlisting>
</section>
</chapter>
<chapter>
<title></title>
<section>
<title></title>
<para></para>
<programlisting></programlisting>
<itemizedlist></itemizedlist>
<orderedlist></orderedlist>
</section>
</chapter>
</book>
My problem occurs when I try to add itemlist, I don't know where I should put it in the code? Everything I try to put it somewhere I get errors.
Can you guys help me finding why it doesn't work? Thanks a lot!
回答1:
Here's what I've done so far (Validation is okay with this part)
Validation should not be ok with that part. You should be getting errors about itemizedlist
and orderedlist
being incomplete. They require at least 1 listitem
(which it sounds like you're trying to add).
Here's a modified version that is valid:
<!DOCTYPE book SYSTEM "simpledocbook.dtd">
<?xml-stylesheet href="docbook.xml" type="application/xml"?>
<book>
<bookinfo>
<title></title>
<author>
<firstname></firstname>
<surname></surname>
</author>
<copyright>
<year></year>
<holder></holder>
</copyright>
</bookinfo>
<chapter>
<title></title>
<section>
<title></title>
<para></para>
<programlisting></programlisting>
</section>
</chapter>
<chapter>
<title></title>
<section>
<title></title>
<para></para>
<programlisting></programlisting>
<itemizedlist>
<listitem>
<para/>
</listitem>
</itemizedlist>
<orderedlist>
<listitem>
<para/>
</listitem>
</orderedlist>
</section>
</chapter>
</book>
I added empty para
elements to the listitem
's because at least 1 of the following are required: para
, programlisting
, itemizedlist
or orderedlist
来源:https://stackoverflow.com/questions/28994708/errors-when-validating-xml-and-dtd