...

View Full Version : PHP DOM - XML Parsing Error: prefix not bound to a namespace



BVBAccelerate
02-12-2009, 06:21 PM
Hey, I'm hoping someone can help me out here. I'm creating an XML document dynamically using PHP and a MySQL database. However, I'm unable to get the XML document to generate properly and I'm getting the error message listed below:


-------------------------------
XML Parsing Error: prefix not bound to a namespace
Location: http://www.cottoneauctions.com/images.php?auction_ID=12
Line Number 2, Column 1:<gallery xmlns:media="http://search.yahoo.com/mrss/" wallCurvature:media="360">
-------------------------------


I cut it off a bit short because the entire XML document ends up being on one line. I'm wondering if someone is able to diagnose why this error is occurring, because I've looked at the source of both documents and they seem to be EXACTLY the same to me, and the actual XML document shows properly in my browser, while the PHP gives me that error. I've used similar code to make other XML files and it works fine for other files on the same site. I've looked into some references to whitespace, and I feel like I've had this problem before, but all of the solutions I've tried seem to not help me at all.

Here is a link to the php that is dynamically creating the XML document:
http://www.cottoneauctions.com/images.php?auction_ID=12

Here is a link to a working model of the XML that I am trying to create:
http://www.cottoneauctions.com/wall/images.xml






Below I'm including the source code for the php file that I'm using to create the XML, in case that helps anyone.

-------------------------------
<?php
require("$_SERVER[DOCUMENT_ROOT]/includes/db_connect.php");

header("Content-type: text/xml"); // --- the header is required so we know this is an XML document

// Start XML file, create parent node

$doc = new DomDocument("1.0", "utf-8");

$node = $doc->createElement("gallery");

$parnode = $doc->appendChild($node);

$parnode->setAttribute("xmlns:media", "http://search.yahoo.com/mrss/");

$parnode->setAttribute("wallCurvature:media", "360");



// --- create the settings node

$node = $doc->createElement("settings");

$settingsNode = $parnode->appendChild($node);



// --- create a mediafolder node for large images

$node = $doc->createElement("mediaFolder");

$mediaFolderLargeNode = $settingsNode->appendChild($node);

$mediaFolderLargeNode->setAttribute("type", "large");

$mediaFolderLargeNode->setAttribute("media", "image");

$mediaFolderLargeNode->nodeValue = "images/";



// --- create a mediafolder node for thumb images

/*

$node = $doc->createElement("mediaFolder");

$mediaFolderThumbNode = $settingsNode->appendChild($node);

$mediaFolderThumbNode->setAttribute("type", "thumbnail");

$mediaFolderThumbNode->setAttribute("media", "image");

$mediaFolderThumbNode->nodeValue = "images/thumbs/";

*/




// --- get all the images for the selected auction from the database

$getImagesQuery = "SELECT title, highres_photo from lotItem, auction WHERE lotItem.auction_ID = auction.auction_ID AND auction.auction_ID = $_REQUEST[auction_ID]";

$getImagesQueryResult = @mysql_query($getImagesQuery);

if(!$getImagesQueryResult){

echo "<p>We could not retrieve the images for this lot item" . mysql_error() . "</p><br> Your sql is $getImagesQueryResult";

}





// --- create the rest of the XML for each auction item

while($lotItemRecord = mysql_fetch_array($getImagesQueryResult)){

// --- create the item element

$node = $doc->createElement("item");

$itemNode = $parnode->appendChild($node);



// --- add the text node to the item node

$node = $doc->createElement("media:text");

$mediaTextNode = $itemNode->appendChild($node);

$lotItemRecord['title'] = str_replace('&', 'and', $lotItemRecord['title']);

$mediaTextNode->nodeValue = $lotItemRecord['title'];



// --- add the content node to the item node

$node = $doc->createElement("media:content");

$mediaContentNode = $itemNode->appendChild($node);

$mediaContentNode->setAttribute('url', $lotItemRecord['highres_photo']);

$mediaContentNode->setAttribute('type', 'image/jpeg');
}

$xmlfile = $doc->saveXML();

echo $xmlfile;?>
-------------------------------

oesxyl
02-12-2009, 07:52 PM
Hey, I'm hoping someone can help me out here. I'm creating an XML document dynamically using PHP and a MySQL database. However, I'm unable to get the XML document to generate properly and I'm getting the error message listed below:


-------------------------------
XML Parsing Error: prefix not bound to a namespace
Location: http://www.cottoneauctions.com/images.php?auction_ID=12
Line Number 2, Column 1:<gallery xmlns:media="http://search.yahoo.com/mrss/" wallCurvature:media="360">
-------------------------------

you use but not declare prefix wallCurvature. I guess this must be media:wallCurvature

best regards

BVBAccelerate
02-12-2009, 08:09 PM
Hey, actually it was a combination of things, but your comment made me realize that the prefix for wallCurvature wasn't even necessary!

I actually posted this in botht the XML and PHP forums and you as well as the PHP forum person were able to combine to solve my problem perfectly, how crazy is that?

Thanks a lot!

WA
02-12-2009, 10:08 PM
Thread cross posted here (http://www.codingforums.com/showthread.php?t=158593), so closing this one. As others have said, in the future, please do not post the same question twice in two different forum categories.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum