Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy PHP DOM - XML Parsing Error: prefix not bound to a namespace

    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;?>
    -------------------------------

  • #2
    Master Coder
    Join Date
    Dec 2007
    Posts
    6,682
    Thanks
    436
    Thanked 890 Times in 879 Posts
    Quote Originally Posted by BVBAccelerate View Post
    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

  • #3
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    4
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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!

  • #4
    WA
    WA is offline
    Administrator
    Join Date
    Mar 2002
    Posts
    2,596
    Thanks
    2
    Thanked 19 Times in 18 Posts
    Thread cross posted here, so closing this one. As others have said, in the future, please do not post the same question twice in two different forum categories.
    - George
    - JavaScript Kit- JavaScript tutorials and 400+ scripts!
    - JavaScript Reference- JavaScript reference you can relate to.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •