Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

XML, XSL, DTD - DTD error... help needed

Status
Not open for further replies.

sn202

IS-IT--Management
Mar 24, 2005
6
GB
Hi all,

Am new to XML and have made some XML pages with a DTD and some XSL stylesheets. Am using Stylus studio development environment and when validating the XML for 2 of my XML pages (about.xml, contact.xml) it says it is valid however the other page (catalogue.xml) is displaying errors. Also when looking at my DTD in firefox and IE it is displaying an error:

---firefox---
Quote:
"XML Parsing Error: syntax error
Location: Line Number 2, Column 1:<!ELEMENT MTA (Company*) >
^"


---IE---
Quote:
Cannot have a DTD declaration outside of a DTD. Error processing resource '
<!ELEMENT MTA (Company*) >
----------^


---catalogue.xml---
Code:

<?xml version="1.0" standalone="no"?>
<?xmlstylesheet href="catalogue.xsl" type="text/xsl"?>
<!DOCTYPE MTA SYSTEM "mta.dtd">
<MTA xmlns:xsi=" xsi:noNamespaceSchemaLocation="mta.dtd">
<Company>
<Catalogue>
<Product>
<Prodname>JVC 28" LCD</Prodname>
<Description>28" flat screen 1 Mega Pixel High quality LCD. Silver, includes
stand</Description>
<Price>£650</Price>
</Product>
<Product>
<Prodname>Phillips 36" Wide Screen TV</Prodname>
<Description>36" Wide Screen, with Dolby digital surround sound, black,
includes Stand</Description>
<Price>£500</Price>
</Product>
<Product>
<Prodname>Sony sterio system</Prodname>
<Description>Sony 5 disk interchanger, double cassette, digital radio, 2 100
Watt speakers, with internal sub woofer</Description>
<Price>£400</Price>
</Product>
<Product>
<Prodname>Bush DVD system</Prodname>
<Description>Bush multi regional DVD, includes 5 speaker surround
sound</Description>
<Price>£100</Price>
</Product>
</Catalogue>
</Company>
</MTA>



---catalogue.xml errors---
Quote:
Validating catalogue.xml...
file:///d:/Documents and Settings/Simon/Desktop/Work/Year 3/hypertext/catalogue.xml:12,14: Element 'Description' is not valid for content model: '(Prodname*,Price,Description*)'
file:///d:/Documents and Settings/Simon/Desktop/Work/Year 3/hypertext/catalogue.xml:18,14: Element 'Description' is not valid for content model: '(Prodname*,Price,Description*)'
file:///d:/Documents and Settings/Simon/Desktop/Work/Year 3/hypertext/catalogue.xml:24,14: Element 'Description' is not valid for content model: '(Prodname*,Price,Description*)'
file:///d:/Documents and Settings/Simon/Desktop/Work/Year 3/hypertext/catalogue.xml:30,14: Element 'Description' is not valid for content model: '(Prodname*,Price,Description*)'
file:///d:/Documents and Settings/Simon/Desktop/Work/Year 3/hypertext/catalogue.xml:32,12: Element 'Catalogue' is not valid for content model: '(About,Catalogue?)'

The XML document catalogue.xml is NOT valid (5 errors)


---DTD---
Code:

<?xml version="1.0" ?>
<!ELEMENT MTA (Company*) >
<!ELEMENT Company (About, Catalogue?)>
<!ELEMENT About (Name?, Owners?, Type?, Location?, Info?, Contact?)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Owners (#PCDATA)>
<!ELEMENT Type (#PCDATA)>
<!ELEMENT Location (#PCDATA)>
<!ELEMENT Info (#PCDATA)>
<!ELEMENT Contact (Phone?, Email?, Post?)>
<!ELEMENT Phone (#PCDATA)>
<!ELEMENT Email (#PCDATA)>
<!ELEMENT Post (#PCDATA)>
<!ELEMENT Catalogue (Product*)>
<!ELEMENT Product (Prodname*, Price, Description*)>
<!ELEMENT Prodname (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ATTLIST MTA xmlns:xsi CDATA #IMPLIED>
<!ATTLIST MTA xsi:noNamespaceSchemaLocation CDATA #IMPLIED>



Any help with this will be much appreciated as I'm on a very tight deadline!!!

regards,

Simon.
 
For Starters...
I believe the DTD should be enclosed in a <!DOCTYPE> tag...
Such As:
Code:
<?xml version="1.0" ?>
[b]<!DOCTYPE MTA [ [/b]

<!ELEMENT MTA (Company*) >
<!ELEMENT Company (About, Catalogue?)>
<!ELEMENT About (Name?, Owners?, Type?, Location?, Info?, Contact?)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Owners  (#PCDATA)>
<!ELEMENT Type  (#PCDATA)>
<!ELEMENT Location  (#PCDATA)>
<!ELEMENT Info  (#PCDATA)>
<!ELEMENT Contact  (Phone?, Email?, Post?)>
<!ELEMENT Phone  (#PCDATA)>
<!ELEMENT Email  (#PCDATA)>
<!ELEMENT Post  (#PCDATA)>
<!ELEMENT Catalogue (Product*)>
<!ELEMENT Product (Prodname*, Price*, Description*)>
<!ELEMENT Prodname (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ATTLIST MTA xmlns:xsi CDATA #IMPLIED>
<!ATTLIST MTA xsi:noNamespaceSchemaLocation CDATA #IMPLIED>

[b]]>[/b]

See this for more on DTDs...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Never mind...
XMLSpy said the only thing it needed was the encoding...
It did not like the <!DOCTYPE X [
It says this is valid:
Code:
<?xml version="1.0" [b]encoding="UTF-8"[/b]?>
<!ELEMENT MTA (Company*) >
<!ELEMENT Company (About, Catalogue?)>
<!ELEMENT About (Name?, Owners?, Type?, Location?, Info?, Contact?)>
<!ELEMENT Name (#PCDATA)>
<!ELEMENT Owners  (#PCDATA)>
<!ELEMENT Type  (#PCDATA)>
<!ELEMENT Location  (#PCDATA)>
<!ELEMENT Info  (#PCDATA)>
<!ELEMENT Contact  (Phone?, Email?, Post?)>
<!ELEMENT Phone  (#PCDATA)>
<!ELEMENT Email  (#PCDATA)>
<!ELEMENT Post  (#PCDATA)>
<!ELEMENT Catalogue (Product*)>
<!ELEMENT Product (Prodname*, Price*, Description*)>
<!ELEMENT Prodname (#PCDATA)>
<!ELEMENT Price (#PCDATA)>
<!ELEMENT Description (#PCDATA)>
<!ATTLIST MTA xmlns:xsi CDATA #IMPLIED>
<!ATTLIST MTA xsi:noNamespaceSchemaLocation CDATA #IMPLIED>

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Thanks for the reply,

Tried adding encoding="UTF-8"? but it didn't solve the problem, still getting the same errors...
any ideas?
 
Your XML file is not valid for that DTD. I've made some changes and this works in IE:
Code:
<?xml version="1.0" standalone="no"?>
<?xmlstylesheet href="catalogue.xsl" type="text/xsl"?>
<!DOCTYPE MTA SYSTEM "mta.dtd">
<MTA xmlns:xsi="[URL unfurl="true"]http://www.w3.org/2001/XMLSchema-instance"[/URL] xsi:noNamespaceSchemaLocation="mta.dtd">
  <Company>
    <About/>
    <Catalogue>
      <Product>
        <Prodname>JVC 28" LCD</Prodname>
        <Price>&#163;650</Price>
        <Description>28" flat screen 1 Mega Pixel High quality LCD. Silver, includes stand</Description>
      </Product>
      <Product>
        <Prodname>Phillips 36" Wide Screen TV</Prodname>
        <Price>&#163;500</Price>
        <Description>36" Wide Screen, with Dolby digital surround sound, black, includes Stand</Description>
      </Product>
      <Product>
        <Prodname>Sony sterio system</Prodname>
        <Price>&#163;400</Price>
        <Description>Sony 5 disk interchanger, double cassette, digital radio, 2 100 Watt speakers, with internal sub woofer</Description>
      </Product>
      <Product>
        <Prodname>Bush DVD system</Prodname>
        <Price>&#163;100</Price>
        <Description>Bush multi regional DVD, includes 5 speaker surround sound</Description>
      </Product>
    </Catalogue>
  </Company>
</MTA>
Note that you cannot use external DTD's with FireFox, they have to be inline or use an XML Schema.

Jon

"There are 10 types of people in the world... those who understand binary and those who don't.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top