homepage Welcome to WebmasterWorld Guest from 54.197.211.197
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member
Home / Forums Index / Code, Content, and Presentation / XML Development
Forum Library, Charter, Moderators: httpwebwitch

XML Development Forum

    
Error in XML feed
Joppiesaus

5+ Year Member



 
Msg#: 3787801 posted 9:51 am on Nov 17, 2008 (gmt 0)

Hello,

Currently I'm creating an "XML-pricefeed" which contains all my actual data that a pricecomparison website can use.

Code of my test XML:

<?php

header("Content-type: text/xml");

$host = "localhost";
$user = "#*$!X";
$pass = "#*$!X";
$database = "#*$!X";

$linkID = mysql_connect($host, $user, $pass) or die("Could not connect to host.");
mysql_select_db($database, $linkID) or die("Could not find database.");

$query = "SELECT * FROM product ORDER BY naam ASC";
$resultID = mysql_query($query, $linkID) or die("Data not found.");

$xml_output = "<?xml version=\"1.0\"?>\n";
$xml_output .= "<entries>\n";

for($x = 0 ; $x < mysql_num_rows($resultID) ; $x++){
$row = mysql_fetch_assoc($resultID);
$xml_output .= "\t<entry>\n";
$xml_output .= "\t\t<naam><![CDATA[" . $row['naam'] . "]]></naam>\n";
$xml_output .= "\t\t<content><![CDATA[" . $row['content'] . "]]></content>\n";
$xml_output .= "\t</entry>\n";
}

$xml_output .= "</entries>";

echo $xml_output;

?>

My output however is all messed up. For instance the output still shows the Cdata tag:

<naam><![CDATA[Name of the product]]></naam>

And like the first 100 rows return empty:

<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
<naam><![CDATA[]]></naam>
<content><![CDATA[]]></content>
</entry>
<entry>
etc etc.

Can anyone assist me in this one?

 

Joppiesaus

5+ Year Member



 
Msg#: 3787801 posted 11:58 am on Nov 17, 2008 (gmt 0)

When I now open the page I get this error warnig:

De XML-pagina kan niet worden weergegeven
Kan XML-invoer niet lezen met opmaakmodel XSL. Herstel de fout en klik vervolgens op de knop Vernieuwen of probeer het later opnieuw.

--------------------------------------------------------------------------------

Er is een ongeldig teken gevonden in de tekstinhoud. Fout bij het verwerken van bron http://www.example.com/test/. ...

<content><![CDATA[Some information about this particular product ...

It says so much as that the XML content can not be read and it gives above row as the one where it crashes.

httpwebwitch

WebmasterWorld Administrator httpwebwitch us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3787801 posted 10:34 pm on Nov 17, 2008 (gmt 0)

the CDATA tags are fine - leave them be. it's a real tag and you've got it just as it ought to be.

here are a couple of tips:
1) see if your db has empty rows in it. If it does, use a WHERE clause in the SQL to select only the rows that contain data.

2) I almost always use while instead for, to loop through a data table

while($row = mysql_fetch_array($resultID)){
$output .= "<naam><![CDATA[".$row['naam']."]]></naam>";
}

you've got a row number where it crashes. Do you see anything unusual about that row?

Joppiesaus

5+ Year Member



 
Msg#: 3787801 posted 9:51 am on Nov 18, 2008 (gmt 0)

Thanks for your tip. I already changed it into a while statement, but great that you also mentioned! :)

I cant see anything odd about the content of that "content" tag. The only "unuasual" character is a "", but this is used a lot in the content, as are other characters like & ? and so on. Shouldn't the CDATA tags take care of this?

httpwebwitch

WebmasterWorld Administrator httpwebwitch us a WebmasterWorld Top Contributor of All Time 10+ Year Member



 
Msg#: 3787801 posted 4:06 pm on Nov 18, 2008 (gmt 0)

yes, CDATA is the right way to handle extended characters like "". Still... try using the entity for (is it &eumlaut; ?) and see if that fixes things...

Have you run the XML through a validation parser? find some way to check the XML for well-formedness... sometimes these things are so well camouflaged in the XML they're maddeningly difficult to spot without mechanical assistance.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / XML Development
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved