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: - Warning: DOMDocument::load() [function.DOMDocument-load]:
-
Element seite content does not follow the DTD, expecting (titel , datei? ,
-
subsection? , preview? , verzeichnis? , bild* , link:author? , link:appendix* ,
-
[…shortened for readability…] , dcterms:subject? , dcterms:title? , dcterms:type?),
-
got (titel datei dcterms:date dcterms:modified dcterms:title )
-
in /var/www/kbl/system/xml/main.struktur.xml, line: 17 in /var/www/kbl/test.php on line 5
and - Warning: DOMDocument::load() [function.DOMDocument-load]:
-
Content model of datei is not determinist: (file | (file? , xsl , xml? , par?))
-
in /var/www/kbl/system/xml/main.struktur.xml, line: 13
-
in /var/www/kbl/test.php on line 5
PHP code: - $xml = new DOMDocument("1.0", "iso-8859-1");
-
$xml->validatOnParse = true;
-
$options = LIBXML_DTDLOAD|LIBXML_DTDATTR|LIBXML_DTDVALID;
-
$test = $xml->load("system/xml/main.struktur.xml", $options);
XML code (snippet, line numbers preserved) - <?xml version="1.0" encoding="iso-8859-1" ?>
-
<!-- project control file -->
-
<!DOCTYPE kbl SYSTEM "../dtd/struktur.dtd">
-
<kbl
-
xmlns="http://www.kulturbeutel-leipzig.net/XML/struktur"
-
xmlns:link="http://www.kulturbeutel-leipzig.net/XML/link"
-
xmlns:dcterms="http://purl.org/dc/terms/">
-
-
<seite id="home" title="Startseite">
-
<titel>Startseite</titel>
-
<datei>
-
<file>home.php</file>
-
</datei>
-
<dcterms:date dc="yes">2008-04-15T08:45+02:00</dcterms:date>
-
<dcterms:modified>2008-09-18T10:55+02:00</dcterms:modified>
-
<dcterms:title dc="yes">Startseite</dcterms:title>
-
</seite>
-
-
<seite id="spielplan" title="Spielplan" cssid="spielplan">
-
<titel>Auftrittstermine</titel>
-
<datei>
-
<xml>spielplan.xml</xml>
-
<xsl>main.spielplan.xsl</xsl>
-
<par>jahr</par>
-
</datei>
-
<dcterms:title dc="yes">Auftrittstermine</dcterms:title>
-
<dcterms:modified>2008-09-18T10:55+02:00</dcterms:modified>
-
<dcterms:date dc="yes">2008-04-15T08:45+02:00</dcterms:date>
-
</seite>
-
-
[…]
-
-
</kbl>
11 7735
Heya, Dormilich.
What's the DTD look like?
that's the DTD - <!ENTITY % latin1 SYSTEM "../dtd/xhtml-lat1.ent">
-
%latin1;
-
<!ENTITY % metalink SYSTEM "../dtd/dtd.meta.ent">
-
%metalink;
-
<!ENTITY % relnavi SYSTEM "../dtd/dtd.link.ent">
-
%relnavi;
-
<!ENTITY % dcmi SYSTEM "../dtd/dtd.dublincore.ent">
-
%dcmi;
-
-
<!ELEMENT kbl (seite+)>
-
<!ATTLIST kbl
-
xmlns CDATA #REQUIRED
-
xmlns:dcterms CDATA #IMPLIED
-
xmlns:link CDATA #IMPLIED
-
>
-
<!ELEMENT seite (titel, datei?, subsection?, preview?, verzeichnis?, bild*, %link.navi;, %dublin.core;)>
-
-
<!ATTLIST seite
-
id ID #REQUIRED
-
title CDATA #REQUIRED
-
cssid CDATA #IMPLIED
-
>
-
<!ELEMENT titel (#PCDATA)>
-
-
<!ELEMENT datei (file | (file?, xsl, xml?, par?))>
-
-
<!ELEMENT file (#PCDATA)>
-
<!ATTLIST file
-
base CDATA #IMPLIED
-
>
-
<!ELEMENT xml (#PCDATA)>
-
-
<!ELEMENT xsl (#PCDATA)>
-
-
<!ELEMENT par (#PCDATA)>
-
-
<!ELEMENT subsection (seite+ | (seite*, collection+))>
-
-
<!ELEMENT collection (titel, subsection+)>
-
<!ATTLIST collection
-
id ID #REQUIRED
-
title CDATA #REQUIRED
-
>
-
<!ELEMENT verzeichnis (#PCDATA)>
-
-
<!ELEMENT bild EMPTY>
-
<!ATTLIST bild
-
id CDATA #IMPLIED
-
src CDATA #REQUIRED
-
title CDATA #REQUIRED
-
hgt CDATA #REQUIRED
-
wdt CDATA #REQUIRED
-
>
-
<!ELEMENT preview (bild | (bild?, longdesc))>
-
-
<!ELEMENT longdesc (#PCDATA)>
dtd.dublincore.ent - the DCMI entities - <!ELEMENT dcterms:abstract (#PCDATA)>
-
<!ELEMENT dcterms:accessRights (#PCDATA)>
-
<!ELEMENT dcterms:accrualMethod (#PCDATA)>
-
<!ELEMENT dcterms:accrualPeriodicity (#PCDATA)>
-
<!ELEMENT dcterms:accrualPolicy (#PCDATA)>
-
<!ELEMENT dcterms:alternative (#PCDATA)>
-
<!ELEMENT dcterms:audience (#PCDATA)>
-
<!ELEMENT dcterms:available (#PCDATA)>
-
[‒and all the other dcmi elements‒]
-
<!ELEMENT dcterms:tableOfContents (#PCDATA)>
-
<!ELEMENT dcterms:temporal (#PCDATA)>
-
<!ELEMENT dcterms:title (#PCDATA)>
-
<!ELEMENT dcterms:type (#PCDATA)>
-
<!ELEMENT dcterms:valid (#PCDATA)>
-
-
<!ATTLIST dcterms:contributor dc (yes|no) "no">
-
<!ATTLIST dcterms:coverage dc (yes|no) "no">
-
<!ATTLIST dcterms:creator dc (yes|no) "no">
-
<!ATTLIST dcterms:date dc (yes|no) "no">
-
<!ATTLIST dcterms:description dc (yes|no) "no">
-
<!ATTLIST dcterms:format dc (yes|no) "no">
-
<!ATTLIST dcterms:identifier dc (yes|no) "no">
-
<!ATTLIST dcterms:language dc (yes|no) "no">
-
<!ATTLIST dcterms:publisher dc (yes|no) "no">
-
<!ATTLIST dcterms:relation dc (yes|no) "no">
-
<!ATTLIST dcterms:rights dc (yes|no) "no">
-
<!ATTLIST dcterms:source dc (yes|no) "no">
-
<!ATTLIST dcterms:subject dc (yes|no) "no">
-
<!ATTLIST dcterms:title dc (yes|no) "no">
-
<!ATTLIST dcterms:type dc (yes|no) "no">
-
dtd.link.ent - link entity definition - <!ELEMENT link:appendix (#PCDATA)>
-
<!ATTLIST link:appendix title CDATA #REQUIRED>
-
-
<!ELEMENT link:author (#PCDATA)>
-
<!ATTLIST link:author title CDATA #REQUIRED>
-
-
<!ELEMENT link:contents (#PCDATA)>
-
<!ATTLIST link:contents title CDATA #REQUIRED>
-
-
<!ELEMENT link:chapter (#PCDATA)>
-
<!ATTLIST link:chapter title CDATA #REQUIRED>
-
-
<!ELEMENT link:section (#PCDATA)>
-
<!ATTLIST link:section title CDATA #REQUIRED>
-
-
<!ELEMENT link:subsection (#PCDATA)>
-
<!ATTLIST link:subsection title CDATA #REQUIRED>
-
-
<!ELEMENT link:index (#PCDATA)>
-
<!ATTLIST link:index title CDATA #REQUIRED>
-
-
<!ELEMENT link:glossary (#PCDATA)>
-
<!ATTLIST link:glossary title CDATA #REQUIRED>
-
-
<!ELEMENT link:copyright (#PCDATA)>
-
<!ATTLIST link:copyright title CDATA #REQUIRED>
-
-
<!ELEMENT link:help (#PCDATA)>
-
<!ATTLIST link:help title CDATA #REQUIRED>
-
-
<!ELEMENT link:bookmark (#PCDATA)>
-
<!ATTLIST link:bookmark title CDATA #REQUIRED>
-
dtd.meta.ent - <!ENTITY % link.navi "link:author?,
-
link:appendix*,
-
link:contents?,
-
link:chapter*,
-
link:section*,
-
link:subsection*,
-
link:index?,
-
link:glossary?,
-
link:copyright?,
-
link:help?,
-
link:bookmark*"
-
>
-
<!ENTITY % dublin.core "dcterms:contributor*,
-
dcterms:coverage?,
-
dcterms:creator*,
-
dcterms:date?,
-
dcterms:description?,
-
dcterms:format?,
-
dcterms:identifier?,
-
dcterms:language?,
-
dcterms:publisher*,
-
dcterms:relation*,
-
dcterms:rights?,
-
dcterms:source?,
-
dcterms:subject?,
-
dcterms:title?,
-
dcterms:type?"
-
>
-
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.
@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.
Only thing I've noticed so far is that the xml and xsl nodes are out of order here: -
# <datei>
-
# <xml>spielplan.xml</xml>
-
# <xsl>main.spielplan.xsl</xsl>
-
# <par>jahr</par>
-
# </datei>
-
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: -
<xs:element name="datei">
-
<xs:complexType>
-
<xs:choice>
-
<xs:element name="file"/>
-
<xs:sequence>
-
<xs:element name="file" minOccurs="0"/>
-
<xs:element name="xsl"/>
-
<xs:element name="xml" minOccurs="0"/>
-
<xs:element name="par" minOccurs="0"/>
-
</xs:sequence>
-
</xs:choice>
-
</xs:complexType>
-
</xs:element>
-
What you need to have: -
<xs:element name="datei">
-
<xs:annotation>
-
<xs:documentation>Comment describing your root element</xs:documentation>
-
</xs:annotation>
-
<xs:complexType>
-
<xs:choice>
-
<xs:sequence>
-
<xs:element name="file"/>
-
<xs:sequence minOccurs="0">
-
<xs:element name="xsl"/>
-
<xs:element name="xml" minOccurs="0"/>
-
<xs:element name="par" minOccurs="0"/>
-
</xs:sequence>
-
</xs:sequence>
-
<xs:sequence>
-
<xs:element name="xsl"/>
-
<xs:element name="xml" minOccurs="0"/>
-
<xs:element name="par" minOccurs="0"/>
-
</xs:sequence>
-
</xs:choice>
-
</xs:complexType>
-
</xs:element>
-
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.
@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?
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.
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
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.
Sign in to post your reply or Sign up for a free account.
Similar topics
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...
|
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...
|
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...
|
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...
|
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"...
|
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...
|
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...
|
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=""...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
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...
|
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...
|
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...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
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: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |