469,270 Members | 1,108 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

Element order issue when validating with DTD

Dormilich
8,651 Expert Mod 8TB
Hello,

I'm trying to validate my XML files against a DTD with PHP 5 and it spits out element order errors (see below). the files validate in FF (once I set the used entities in the local DTD part, but that's a FF issue not applying to PHP). From a simpler DTD I know that element order must be the same in DTD and XML but I don't know what the cause is for error 1 (once you leave out the optional elements, it looks the same to me, even the order).

the other issue is that the nested construct seems not to be recognized by libxml somehow.

can anyone help me here?

thanks

Error messages:
Expand|Select|Wrap|Line Numbers
  1. Warning: DOMDocument::load() [function.DOMDocument-load]: 
  2. Element seite content does not follow the DTD, expecting (titel , datei? , 
  3. subsection? , preview? , verzeichnis? , bild* , link:author? , link:appendix* , 
  4. […shortened for readability…] , dcterms:subject? , dcterms:title? , dcterms:type?), 
  5. got (titel datei dcterms:date dcterms:modified dcterms:title ) 
  6. in /var/www/kbl/system/xml/main.struktur.xml, line: 17 in /var/www/kbl/test.php on line 5
and
Expand|Select|Wrap|Line Numbers
  1. Warning: DOMDocument::load() [function.DOMDocument-load]: 
  2. Content model of datei is not determinist: (file | (file? , xsl , xml? , par?)) 
  3. in /var/www/kbl/system/xml/main.struktur.xml, line: 13 
  4. in /var/www/kbl/test.php on line 5
PHP code:
Expand|Select|Wrap|Line Numbers
  1. $xml = new DOMDocument("1.0", "iso-8859-1");
  2. $xml->validatOnParse = true;
  3. $options = LIBXML_DTDLOAD|LIBXML_DTDATTR|LIBXML_DTDVALID;
  4. $test = $xml->load("system/xml/main.struktur.xml", $options);
XML code (snippet, line numbers preserved)
Expand|Select|Wrap|Line Numbers
  1. <?xml version="1.0" encoding="iso-8859-1" ?>
  2. <!-- project control file -->
  3. <!DOCTYPE kbl SYSTEM "../dtd/struktur.dtd">
  4. <kbl
  5.     xmlns="http://www.kulturbeutel-leipzig.net/XML/struktur"
  6.     xmlns:link="http://www.kulturbeutel-leipzig.net/XML/link"
  7.     xmlns:dcterms="http://purl.org/dc/terms/">
  8.  
  9. <seite id="home" title="Startseite">
  10.   <titel>Startseite</titel>
  11.   <datei>
  12.     <file>home.php</file>
  13.   </datei>
  14.   <dcterms:date dc="yes">2008-04-15T08:45+02:00</dcterms:date>
  15.   <dcterms:modified>2008-09-18T10:55+02:00</dcterms:modified>
  16.   <dcterms:title dc="yes">Startseite</dcterms:title>
  17. </seite>
  18.  
  19. <seite id="spielplan" title="Spielplan" cssid="spielplan">
  20.   <titel>Auftrittstermine</titel>
  21.   <datei>
  22.     <xml>spielplan.xml</xml>
  23.     <xsl>main.spielplan.xsl</xsl>
  24.     <par>jahr</par>
  25.   </datei>
  26.   <dcterms:title dc="yes">Auftrittstermine</dcterms:title>
  27.   <dcterms:modified>2008-09-18T10:55+02:00</dcterms:modified>
  28.   <dcterms:date dc="yes">2008-04-15T08:45+02:00</dcterms:date>
  29. </seite>
  30.  
  31. […]
  32.  
  33. </kbl>
Dec 1 '08 #1
11 7465
pbmods
5,821 Expert 4TB
Heya, Dormilich.

What's the DTD look like?
Dec 2 '08 #2
Dormilich
8,651 Expert Mod 8TB
that's the DTD
Expand|Select|Wrap|Line Numbers
  1. <!ENTITY % latin1 SYSTEM "../dtd/xhtml-lat1.ent">
  2. %latin1;
  3. <!ENTITY % metalink SYSTEM "../dtd/dtd.meta.ent">
  4. %metalink;
  5. <!ENTITY % relnavi SYSTEM "../dtd/dtd.link.ent">
  6. %relnavi;
  7. <!ENTITY % dcmi SYSTEM "../dtd/dtd.dublincore.ent">
  8. %dcmi;
  9.  
  10. <!ELEMENT kbl           (seite+)>
  11. <!ATTLIST kbl
  12.     xmlns               CDATA   #REQUIRED
  13.     xmlns:dcterms       CDATA   #IMPLIED
  14.     xmlns:link          CDATA   #IMPLIED
  15. >
  16. <!ELEMENT seite         (titel, datei?, subsection?, preview?, verzeichnis?, bild*, %link.navi;, %dublin.core;)>
  17.  
  18. <!ATTLIST seite 
  19.     id                  ID      #REQUIRED
  20.     title               CDATA   #REQUIRED
  21.     cssid               CDATA   #IMPLIED
  22. >
  23. <!ELEMENT titel         (#PCDATA)>
  24.  
  25. <!ELEMENT datei         (file | (file?, xsl, xml?, par?))>
  26.  
  27. <!ELEMENT file          (#PCDATA)>
  28. <!ATTLIST file 
  29.     base                CDATA   #IMPLIED
  30. >
  31. <!ELEMENT xml           (#PCDATA)>
  32.  
  33. <!ELEMENT xsl           (#PCDATA)>
  34.  
  35. <!ELEMENT par           (#PCDATA)>
  36.  
  37. <!ELEMENT subsection    (seite+ | (seite*, collection+))>
  38.  
  39. <!ELEMENT collection    (titel, subsection+)>
  40. <!ATTLIST collection 
  41.     id                  ID      #REQUIRED
  42.     title               CDATA   #REQUIRED
  43. >
  44. <!ELEMENT verzeichnis   (#PCDATA)>
  45.  
  46. <!ELEMENT bild          EMPTY>
  47. <!ATTLIST bild
  48.     id                  CDATA   #IMPLIED
  49.     src                 CDATA   #REQUIRED
  50.     title               CDATA   #REQUIRED
  51.     hgt                 CDATA   #REQUIRED
  52.     wdt                 CDATA   #REQUIRED
  53. >
  54. <!ELEMENT preview       (bild | (bild?, longdesc))>
  55.  
  56. <!ELEMENT longdesc      (#PCDATA)>
dtd.dublincore.ent - the DCMI entities
Expand|Select|Wrap|Line Numbers
  1. <!ELEMENT dcterms:abstract              (#PCDATA)>
  2. <!ELEMENT dcterms:accessRights          (#PCDATA)>
  3. <!ELEMENT dcterms:accrualMethod         (#PCDATA)>
  4. <!ELEMENT dcterms:accrualPeriodicity    (#PCDATA)>
  5. <!ELEMENT dcterms:accrualPolicy         (#PCDATA)>
  6. <!ELEMENT dcterms:alternative           (#PCDATA)>
  7. <!ELEMENT dcterms:audience              (#PCDATA)>
  8. <!ELEMENT dcterms:available             (#PCDATA)>
  9. [‒and all the other dcmi elements‒]
  10. <!ELEMENT dcterms:tableOfContents       (#PCDATA)>
  11. <!ELEMENT dcterms:temporal              (#PCDATA)>
  12. <!ELEMENT dcterms:title                 (#PCDATA)>
  13. <!ELEMENT dcterms:type                  (#PCDATA)>
  14. <!ELEMENT dcterms:valid                 (#PCDATA)>
  15.  
  16. <!ATTLIST dcterms:contributor dc (yes|no)  "no">
  17. <!ATTLIST dcterms:coverage    dc (yes|no)  "no">
  18. <!ATTLIST dcterms:creator     dc (yes|no)  "no">
  19. <!ATTLIST dcterms:date        dc (yes|no)  "no">
  20. <!ATTLIST dcterms:description dc (yes|no)  "no">
  21. <!ATTLIST dcterms:format      dc (yes|no)  "no">
  22. <!ATTLIST dcterms:identifier  dc (yes|no)  "no">
  23. <!ATTLIST dcterms:language    dc (yes|no)  "no">
  24. <!ATTLIST dcterms:publisher   dc (yes|no)  "no">
  25. <!ATTLIST dcterms:relation    dc (yes|no)  "no">
  26. <!ATTLIST dcterms:rights      dc (yes|no)  "no">
  27. <!ATTLIST dcterms:source      dc (yes|no)  "no">
  28. <!ATTLIST dcterms:subject     dc (yes|no)  "no">
  29. <!ATTLIST dcterms:title       dc (yes|no)  "no">
  30. <!ATTLIST dcterms:type        dc (yes|no)  "no">
  31.  
dtd.link.ent - link entity definition
Expand|Select|Wrap|Line Numbers
  1. <!ELEMENT link:appendix (#PCDATA)>
  2. <!ATTLIST link:appendix title   CDATA   #REQUIRED>
  3.  
  4. <!ELEMENT link:author   (#PCDATA)>
  5. <!ATTLIST link:author   title   CDATA   #REQUIRED>
  6.  
  7. <!ELEMENT link:contents (#PCDATA)>
  8. <!ATTLIST link:contents title   CDATA   #REQUIRED>
  9.  
  10. <!ELEMENT link:chapter (#PCDATA)>
  11. <!ATTLIST link:chapter title   CDATA   #REQUIRED>
  12.  
  13. <!ELEMENT link:section (#PCDATA)>
  14. <!ATTLIST link:section title   CDATA   #REQUIRED>
  15.  
  16. <!ELEMENT link:subsection (#PCDATA)>
  17. <!ATTLIST link:subsection title   CDATA   #REQUIRED>
  18.  
  19. <!ELEMENT link:index (#PCDATA)>
  20. <!ATTLIST link:index title   CDATA   #REQUIRED>
  21.  
  22. <!ELEMENT link:glossary (#PCDATA)>
  23. <!ATTLIST link:glossary title   CDATA   #REQUIRED>
  24.  
  25. <!ELEMENT link:copyright (#PCDATA)>
  26. <!ATTLIST link:copyright title   CDATA   #REQUIRED>
  27.  
  28. <!ELEMENT link:help (#PCDATA)>
  29. <!ATTLIST link:help title   CDATA   #REQUIRED>
  30.  
  31. <!ELEMENT link:bookmark (#PCDATA)>
  32. <!ATTLIST link:bookmark title   CDATA   #REQUIRED>
  33.  
dtd.meta.ent
Expand|Select|Wrap|Line Numbers
  1. <!ENTITY % link.navi   "link:author?, 
  2.                         link:appendix*, 
  3.                         link:contents?, 
  4.                         link:chapter*, 
  5.                         link:section*, 
  6.                         link:subsection*, 
  7.                         link:index?, 
  8.                         link:glossary?, 
  9.                         link:copyright?, 
  10.                         link:help?, 
  11.                         link:bookmark*"
  12. >
  13. <!ENTITY % dublin.core "dcterms:contributor*, 
  14.                         dcterms:coverage?, 
  15.                         dcterms:creator*, 
  16.                         dcterms:date?, 
  17.                         dcterms:description?, 
  18.                         dcterms:format?, 
  19.                         dcterms:identifier?, 
  20.                         dcterms:language?, 
  21.                         dcterms:publisher*, 
  22.                         dcterms:relation*, 
  23.                         dcterms:rights?, 
  24.                         dcterms:source?, 
  25.                         dcterms:subject?, 
  26.                         dcterms:title?, 
  27.                         dcterms:type?"
  28. >
  29.  
Dec 2 '08 #3
pbmods
5,821 Expert 4TB
Just in case Firefox is being crazy, I'm going to go ahead and move this thread to the XML forum for a bit and have our XML experts weigh in.
Dec 2 '08 #4
Dormilich
8,651 Expert Mod 8TB
@pbmods
well yes, but FF doesn't play a role in the problem..... maybe jkmyoung does know anything that can help. but to me it seemed like a problem DOMDocument has with validation/DTDs.
maybe I have to switch to relaxng or xml schema to get it working.
Dec 2 '08 #5
jkmyoung
2,057 Expert 2GB
Only thing I've noticed so far is that the xml and xsl nodes are out of order here:
Expand|Select|Wrap|Line Numbers
  1. #   <datei>
  2. #     <xml>spielplan.xml</xml>
  3. #     <xsl>main.spielplan.xsl</xsl>
  4. #     <par>jahr</par>
  5. #   </datei>
  6.  
Dec 3 '08 #6
jkmyoung
2,057 Expert 2GB
Sorry, but my dtd is not great so I'm speaking in terms of xml schema. Once you find the file element, the parser doesn't know which branch to take. You need to restructure the dtd so the choice of branches depends on the first element.
What you have now:
Expand|Select|Wrap|Line Numbers
  1. <xs:element name="datei">
  2.     <xs:complexType>
  3.         <xs:choice>
  4.             <xs:element name="file"/>
  5.             <xs:sequence>
  6.                 <xs:element name="file" minOccurs="0"/>
  7.                 <xs:element name="xsl"/>
  8.                 <xs:element name="xml" minOccurs="0"/>
  9.                 <xs:element name="par" minOccurs="0"/>
  10.             </xs:sequence>
  11.         </xs:choice>
  12.     </xs:complexType>
  13. </xs:element>
  14.  
What you need to have:
Expand|Select|Wrap|Line Numbers
  1. <xs:element name="datei">
  2.     <xs:annotation>
  3.         <xs:documentation>Comment describing your root element</xs:documentation>
  4.     </xs:annotation>
  5.     <xs:complexType>
  6.         <xs:choice>
  7.             <xs:sequence>
  8.                 <xs:element name="file"/>
  9.                 <xs:sequence minOccurs="0">
  10.                     <xs:element name="xsl"/>
  11.                     <xs:element name="xml" minOccurs="0"/>
  12.                     <xs:element name="par" minOccurs="0"/>
  13.                 </xs:sequence>
  14.             </xs:sequence>
  15.             <xs:sequence>
  16.                 <xs:element name="xsl"/>
  17.                 <xs:element name="xml" minOccurs="0"/>
  18.                 <xs:element name="par" minOccurs="0"/>
  19.             </xs:sequence>
  20.         </xs:choice>
  21.     </xs:complexType>
  22. </xs:element>
  23.  
The first choice has the file element, the 2nd does not. The nested sequence in the first choice is conditional as well, representing what happens when there is only the file element.
Note that the xsl part comes in a sequence, so you can't have just xml or par elements by themselves without the xsl element.
Dec 3 '08 #7
Dormilich
8,651 Expert Mod 8TB
@jkmyoung
for me the element order doesn't matter, but obviously for the validator.... (it seem to choke on the OR operator) would you recommend me switching to XML Schema?
Dec 3 '08 #8
jkmyoung
2,057 Expert 2GB
Changing to regexp form:
Current:
(file | (file?, xsl, xml?, par?))

Suggested change:
((file, (xsl, xml?, par?)?) | (xsl, xml?, par?))

Sorry, I didn't write it in RE in the first place.
Dec 3 '08 #9
Dormilich
8,651 Expert Mod 8TB
thanks jkmyoung, it's working. if I order the elements it should resolve the element order warnings too.

if I should switch someday to XML Schema, is there something like element order too? (I hope not)

regards, Dormi
Dec 3 '08 #10
jkmyoung
2,057 Expert 2GB
By default, most of the structures use element order. The only ones I can remember which don't are xsd:all or xsd:choice.
Of course, you can always use an unbounded sequence with all optional elements, for any ordering and number of elements.
Dec 3 '08 #11
Dormilich
8,651 Expert Mod 8TB
I'll bear that in mind.
Dec 3 '08 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by Wole Ogunremi | last post: by
1 post views Thread by Alejandro Calbazana | last post: by
1 post views Thread by Mark Spencer | last post: by
1 post views Thread by Nathan Alden | last post: by
14 posts views Thread by webEater | last post: by
1 post views Thread by =?Utf-8?B?bGpsZXZlbmQy?= | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.