473,385 Members | 1,890 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Element order issue when validating with DTD

Dormilich
8,658 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 7732
pbmods
5,821 Expert 4TB
Heya, Dormilich.

What's the DTD look like?
Dec 2 '08 #2
Dormilich
8,658 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,658 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,658 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,658 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,658 Expert Mod 8TB
I'll bear that in mind.
Dec 3 '08 #12

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

Similar topics

6
by: Wole Ogunremi | last post by:
I guess this is a well asked question but it is tripping me up! I'm putting a forum together allowing xhtml markup content. I am validating against a schema but getting "Could not find schema...
1
by: Alejandro Calbazana | last post by:
Hello, Should the XmlValidatingReader validating xml against an xsd serially (e.g. - does the XML have to be in the correct position in order for a document to be valid)? For example, I am...
1
by: Mark Spencer | last post by:
Hey there, I'm running into an issue and wondered if any of you XML gurus know a solution. I'm currently using XML as a data transport mechanism between two applications and an XML schema for...
1
by: beachnut | last post by:
Hi, all. This should be pretty easy: When parsing my XmlDocument object with a validating reader, what's the proper way to detect when it "exits" an element's block? It's the first time I've...
1
by: Nathan Alden | last post by:
I have an XSD defined as the following: <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"...
0
by: BC3Tech | last post by:
I'm creating a system that uses XML to store an audit trail of the steps that it has been through in the system. The way the schema is defined, there is a "Tag" for every application that...
10
by: sp | last post by:
I create an xml file in a text editor: <?xml version="1.0" encoding="utf-8"?> <elts> <elt id="1" class="c1">content1</elt> <elt id="2" class="c1">content2</elt> </elts> Then I load the file...
14
by: webEater | last post by:
I have a problem, it's not browser specific, and I don't get a solution. I have an (X)HTML document, I show you a part of it: .... <!--<div class="pad">--> <div id="eventImages"><img src=""...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that controls do not raise a Validating event if they are contained in a ToolStripDropDown via a ToolStripControlHost item. Please run the following sample and follow the instructions...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.