Jump to content

[SOLVED] PHP to XML maybe simple error


AE117

Recommended Posts

Heres my code to start with

 

<?php

$host = "localhost";
$user = "";
$pass = "";
$database = "";


if(!$dbconnect = mysql_connect($host, $user, $pass)) {
   echo "Connection failed to the host 'localhost'.";
   exit;
} // if
if (!mysql_select_db($database)) {
   echo "Cannot connect to database";
   exit;
} // if

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

$table_id = 'ost_media';
$query = "SELECT * FROM $table_id";
$dbresult = mysql_query($query, $dbconnect);

$outer_table = 'ost_media';
$query = "SELECT * FROM $outer_table WHERE media_access='300zx Twin Turbo vs ZX10R'";
$resouter = mysql_query($query, $dbconnect);

$inner_table = 'ost_media';
$query = "SELECT * FROM $inner_table WHERE media_title='300zx Twin Turbo vs ZX10R'";
$resinner = mysql_query($query, $dbconnect);


$dom = new DomDocument('1.0','utf-8');

$root = $dom->createElement('featureset');
$root = $dom->appendChild($root);
$outer = $dom->createElement('album');
$outer = $root->appendChild($outer);

$row = mysql_fetch_assoc($resouter);

// process all rows of the inner/many/child table
while ($row = @mysql_fetch_assoc($resinner)) {
    // add node for each record
    $inner = $dom->createElement('song');
    $inner = $outer->appendChild($inner);
$inner->setAttribute('name', 'title');
$inner->setAttribute('duration', '3:15');
$inner->setAttribute('buy', 'false');
$inner->setAttribute('download', 'true');
$inner->setAttribute('downloadsource', 'download/song1.mp3');
$value = $dom->createTextNode('songs/song1.mp3');
$value = $inner->appendChild($value);
    // add a child node for each field
    foreach ($row as $fieldname => $fieldvalue) {
	    $inner = $dom->createElement($outer_table);
		$outer->setAttribute('name', 'Shock Value');
		$outer->setAttribute('author', 'TimberLand');
		$outer->setAttribute('imageUrl', 'images/Timbaland/image.jpg');
		$outer->setAttribute('link', 'http://eevoke.com');

    } // foreach

} // while


// get completed xml document
$xml_string = $dom->saveXML();
echo $xml_string;

?>

 

When I test it in firefox I get this error or statment

 

"XML Parsing Error: junk after document element

Location: http://music.eevoke.com/project/deploy/player/xml/testing.php

Line Number 3, Column 1:<?xml version="1.0" encoding="utf-8"?>

^"

 

And then when I test it i Internet explore 8 i get

 

"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 'http://music.eevoke.com/project/deploy...

 

<featureset><album name="Shock Value" author="TimberLand" imageUrl="images/Timbaland/image.jpg" link="http://eevoke...

"

 

Can anyone make somthing out of these I cant see anything myself.

 

Link to comment
https://forums.phpfreaks.com/topic/154816-solved-php-to-xml-maybe-simple-error/
Share on other sites

Can you paste the code that is outputted, via view source?

 

Here is the view source

 

<?xml version="1.0" encoding="utf-8"?>
<featureset><album name="Shock Value" author="TimberLand" imageUrl="images/Timbaland/image.jpg" link="http://eevoke.com"><song name="title" duration="3:15" buy="false" download="true" downloadsource="download/song1.mp3">songs/song1.mp3</song></album></featureset>

 

Looks good right thats what is really bugging me

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.