Jump to content

php to write the xml


Recommended Posts

I have data in a databsae that i want to convert into xml.

When i test the outputted php file i get valid xml.

 

However when i try to load this xml i get the following error

 

Warning: simplexml_load_file() [function.simplexml-load-file]: parts/xml/userMedia.php:58: parser error : Start tag expected, '<' not found in C:\..........\viewMediaFolder.php on line 52

 

The code i am using to output the xml is:

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

for($i=0;$i<count($mediaId_array); $i++){ 
    $xml_output .= "\t<media>\n"; 
    $xml_output .= "\t\t<mediaId>".$mediaId_array[$i]."</mediaId>\n"; 
    $xml_output .= "\t\t<mediaType>".$mediaType_array[$i]."</mediaType>\n"; 
$xml_output .= "\t\t<mediaTitle>".$mediaTitle_array[$i]."</mediaTitle>\n"; 
    $xml_output .= "\t\t<mediaFilename>".$mediaFilename_array[$i]."</mediaFilename>\n"; 
    $xml_output .= "\t\t<mediaThumbnail>".$mediaImageFilename_array[$i]."</mediaThumbnail>\n"; 
    $xml_output .= "\t\t<folderId>".$folderId_array[$i]."</folderId>\n";
    $xml_output .= "\t\t<dateCreated>".$dateCreated_array[$i]."</dateCreated>\n";
$xml_output .= "\t</media>\n"; 
} 

$xml_output .= "</mediaAll>"; 


print $xml_output;

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/
Share on other sites

Is it possible to load xml from a php file.

 

$xml = simplexml_load_file('xml/test.php');

 

the test.php file echos valid xml with xml headers... however it doesn't seem to work for me... this tutorial says that this can be done

 

http://www.kirupa.com/web/mysql_xml_php.htm

 

Anyone know if this is defo possible or where im going wrong... because if i change the test.php file for an actual xml file it works fine.

 

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/#findComment-850303
Share on other sites

Is this a playlist generator?

 

//query here

echo '<?xml version="1.0" encoding="UTF-8"?><playlist xmlns="http://xspf.org/ns/0/" version="1"><title>mixmedia</title> <tracklist>';

  echo"<track>
      <title>".$row['title']."</title>
      <location>".$file."</location>
       <duration>".$row['video_length']."</duration>
      <image>/thumb/".$row['id'].".jpg</image>
    </track>";

echo '</tracklist></playlist>';

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/#findComment-850308
Share on other sites

It isn't a playlist generator but it is the same idea...

it is a php script that grabs data from database and outputs it as xml...

 

however i can't even load a script that simply echos the xml like so...

 

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

print'<?xml version="1.0"?>

<catalog>

  <book id="bk101">

      <author>Gambardella, Matthew</author>

      <title>XML Developer\'s Guide</title>

      <genre>Computer</genre>

      <price>44.95</price>

      <publish_date>2000-10-01</publish_date>

      <description>An in-depth look at creating applications

      with XML.</description>

  </book>

</catalog>';

 

 

when i try and load this page

 

$xml = simplexml_load_file('xml/test.php');

 

i get an error... any ideas?

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/#findComment-850321
Share on other sites

Answer don't use

$xml=simplexml_load_file('xml/test.php');

 

because it no load the php filetype... it only load xml filetype...

 

instead in the php script that creates the xml.. simply give the generated xml a var name for example

$xmlFromExernal script (dont echo/print it out)

 

then include this php script in the php file that you are trying to use to display the xml data..

and use...

 

$xml = simplexml_load_string($xmlFromExernal script);

 

bingo-bango.

 

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/#findComment-850337
Share on other sites

Answer don't use

$xml=simplexml_load_file('xml/test.php');

 

because it no load the php filetype... it only load xml filetype...

 

instead in the php script that creates the xml.. simply give the generated xml a var name for example

$xmlFromExernal script (dont echo/print it out)

 

then include this php script in the php file that you are trying to use to display the xml data..

and use...

 

$xml = simplexml_load_string($xmlFromExernal script);

 

bingo-bango.

 

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/#findComment-850339
Share on other sites

The reason calling $xml=simplexml_load_file('xml/test.php') won't work is because the test.php script never gets parsed by php. In order for it to be parsed you would need to call it via a url. eg;

 

simplexml_load_file('http://yourdomain.com/xml/test.php');

 

Makes perfect sense doesn't it?

Link to comment
https://forums.phpfreaks.com/topic/161119-php-to-write-the-xml/#findComment-850364
Share on other sites

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.