XML help needed

Status
Not open for further replies.

swollenpickles

New member
Dec 1, 2006
121
1
0
Australia
www.swollenpickles.com
Are there any XML gurus out there? I'm an XML noob and am playing around with an XML file. When I try to validate it, I get this error message:
Error Code: -1072898024
Error Reason: Text is not allowed in this context according to DTD/Schema.
Expecting: reissue.
Error Line: 43
What does that mean? How do i fix it?
 
Last edited:


Well, to help you with that, you'll need to post an example of the XML.

Normally, a DTD is used to validate an XML file, it tells you which kind of data is allowed where.

::emp::
 
To expand on this:

You are probably using an XML file you found somewhere or one that does something for an app/script.

The DTD that is referenced in the XML file defines exactly what data can go where.

This becomes important when XML files are used for applications, especially when the data is used to populate a database.

You are basically trying to put text in a place where the DTD won't allow it.

Either change the DTD or look at what the XML file is supposed to be doing.

::emp::
 
Thanks, it's a file I created myself (I haven't taken it from anywhere). It's only supposed to be basic so I pick up a bit of what XML is all about.

Here is what I have:

Code:
<?xml version="1.0"?>

<!-- Link to the XSL stylesheet -->

<?xml-stylesheet type="text/xsl" href=""?>

<!-- Start of the cdlist DTD -->

<!DOCTYPE cdlist [

   <!ELEMENT cdlist            (cd+)>
   <!ELEMENT cd             (album,artist,year,runningtime,
                    tuners,bridge,neck,body,image)>

   <!ELEMENT album            (#PCDATA)>
   <!ELEMENT artist            (#PCDATA)>
   <!ELEMENT year            (reissue)>

      <!ELEMENT reissue            (#PCDATA)>
   
   <!ELEMENT runningtime        (min,sec)>
      <!ELEMENT min            (#PCDATA)>
      <!ELEMENT sec            (#PCDATA)>

   <!ELEMENT image            (source,height,width,
                    alt,title)>

      <!ELEMENT source            (#PCDATA)>
      <!ELEMENT height            (#PCDATA)>
      <!ELEMENT width            (#PCDATA)>
      <!ELEMENT alt            (#PCDATA)>
      <!ELEMENT title            (#PCDATA)>

]>

<!-- Start of the XML content -->

<cdlist>

   <cd>
    <album>Album</album>
    <artist>Artist</artist>
    <year>1975</year>
       <reissue>2006</reissue>
    <runningtime>time</runningtime>
       <min>40</min>
       <sec>15</sec>
    <images>
       <source>imgs/cd.gif</source>
       <height>294</height>
       <width>101</width>
       <alt>cd</alt>
       <title>cd</title>
    </image>
   </cd>

</cdlist>
 
You have a broken XML here. Those don't match up.

<images>
<source>imgs/cd.gif</source>
<height>294</height>
<width>101</width>
<alt>cd</alt>
<title>cd</title>
</image>
 
OK, you have several more issues with your DTD.

for example, THIS snippet
Code:
   <!ELEMENT runningtime        (min,sec)>
      <!ELEMENT min            (#PCDATA)>
      <!ELEMENT sec            (#PCDATA)>

Tells me that the element runningtime only has the child elements min and sec

But you enter data in it and don't include the child elements as such.

THIS:

Code:
 <runningtime>time</runningtime>
       <min>40</min>
      <sec>15</sec>

Has to look like this:
Code:
    <runningtime>
       <min>40</min>
       <sec>15</sec>
    </runningtime>

same for some other Tags. For example: year.

::emp::
 
This one validates for me:

Code:
<?xml version="1.0"?>

<!-- Link to the XSL stylesheet -->

<?xml-stylesheet type="text/xsl" href=""?>

<!-- Start of the cdlist DTD -->

<!DOCTYPE cdlist [

   <!ELEMENT cdlist            (cd+)>
   <!ELEMENT cd             (album,artist,year,runningtime,
                    image)>

   <!ELEMENT album            (#PCDATA)>
   <!ELEMENT artist            (#PCDATA)>
   <!ELEMENT year            (reissue)>

      <!ELEMENT reissue            (#PCDATA)>
   
   <!ELEMENT runningtime        (min,sec)>
      <!ELEMENT min            (#PCDATA)>
      <!ELEMENT sec            (#PCDATA)>

   <!ELEMENT image            (source,height,width,
                    alt,title)>

      <!ELEMENT source            (#PCDATA)>
      <!ELEMENT height            (#PCDATA)>
      <!ELEMENT width            (#PCDATA)>
      <!ELEMENT alt            (#PCDATA)>
      <!ELEMENT title            (#PCDATA)>

]>

<!-- Start of the XML content -->

<cdlist>

   <cd>
    <album>Album</album>
    <artist>Artist</artist>
    <year>
       <reissue>2006</reissue>
</year>
    <runningtime>
       <min>40</min>
       <sec>15</sec>
    </runningtime>
    <image>
       <source>imgscd.gif</source>
       <height>294</height>
       <width>101</width>
       <alt>cd</alt>
       <title>cd</title>
    </image>
   </cd>

</cdlist>
 
OK, you have several more issues with your DTD.

for example, THIS snippet
Code:
   <!ELEMENT runningtime        (min,sec)>
      <!ELEMENT min            (#PCDATA)>
      <!ELEMENT sec            (#PCDATA)>
Tells me that the element runningtime only has the child elements min and sec

But you enter data in it and don't include the child elements as such.

THIS:

Code:
 <runningtime>time</runningtime>
       <min>40</min>
      <sec>15</sec>
Has to look like this:
Code:
    <runningtime>
       <min>40</min>
       <sec>15</sec>
    </runningtime>
same for some other Tags. For example: year.

::emp::

Thanks!! That was really doing my freakin head in!!
 
Haha, if this makes money I'll throw some your way! At the moment I'm not exactly rolling in it! :p

Rather than payment, I do have another question though. In the case where you have image data stored in the xml file and you want to call it up in and xsl file, how do you do that? Is it possible?

So in the example I'm screwing around with, I want to display the cd cover, along with the title and other text based info. How does that work?

Code:
    <image>
       <source>imgs/cd.gif</source>
       <height>294</height>
       <width>101</width>
       <alt>cd</alt>
       <title>cd</title>
    </image>
 
Status
Not open for further replies.