Results 1 to 2 of 2

Thread: problem displaying mysql data as xml

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Apr 2005
    Posts
    1,907

    problem displaying mysql data as xml

    Hi all i am trying to use the following code to output mysql data as xml but i keep getting this error:


    The XML page cannot be displayed
    Cannot view XML input using XSL style sheet. Please correct the error and then click the Refresh button, or try again later.

    Only one top level element is allowed in an XML document. Error processing resource
    i test the code without making xml and it output the data correctly so there is not problem with database connection. I hope you guys show me how to fix this problem and output the xml data correctly.Looking forward for replies.

    PHP Code:
    <?php
    header
    ("Cache-Control: no-cache, must-revalidate");
        
    header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
    $server   "mysql.somesite.com"// MySQL hostname
    $username "user"// MySQL username
    $password "test"// MySQL password
    $dbname   "test_db"// MySQL db name

    $db mysql_connect($server$username$password) or die(mysql_error());
          
    mysql_select_db($dbname) or die(mysql_error());


    header('Content-type: application/xml'); 

    $res mysql_query('SELECT * FROM music1 ORDER by date') or die('<error>'.mysql_error().'</error>'); 

    echo 
    '<playlist>'
    while(
    $row mysql_fetch_assoc($res)){ 
      echo 
    '<song>'
      echo 
    '<artist>'.$row['artist'].'</artist>'
      echo 
    '<name>'.$row['name'].'</name>'
      echo 
    '<image>'.$row['pic'].'</image>'
      echo 
    '<rating>'.$row['ids'].'</rating>'
      echo 
    '<songid>'.$row['date'].'</songid>'
      echo 
    '<totalvotes>'.$row['who_sessid'].'</totalvotes>'
      echo 
    '</song>'

    echo 
    '</playlist>';  


    ?>

  2. #2
    PowerPoster
    Join Date
    Sep 2003
    Location
    Edmonton, AB, Canada
    Posts
    2,629

    Re: problem displaying mysql data as xml

    right click -> view source. paste the XML you're getting.
    Like Archer? Check out some Sterling Archer quotes.

Posting Permissions

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



Click Here to Expand Forum to Full Width