1

I use the JW player to load a XML playlist. It works fine when I manually write the XML file, but not when I use php to parse...

I want it to look like this:

<rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/" xmlns:jwplayer="http://developer.longtailvideo.com/trac/"> 
<channel>
  <item>
    <title>Albert</title>
    <media:content url="../movies/hi.mp4" />
    <description></description>
    <jwplayer:duration>10</jwplayer:duration>
  </item>
</channel>
</rss>

The first problem is the <rss version="2.0" ... It forces the headers to be: <?xml version="1.0"?>

The second problem is the <media:content url="" ... How can I print out that with php ?

The third problem is how to add the end rss </rss>

My code is:

<?php 
  $channel = array(); 
  $channel [] = array( 
  'title' => 'Albert', 
  'content' => 'filmer/c1.jpg', 
  'duration' => "10" 
  ); 
  $channel [] = array( 
  'title' => 'Claud', 
  'content' => 'filmer/c2.jpg', 
  'duration' => "10" 
  ); 

  $doc = new DOMDocument();
  $doc->formatOutput = true; 

  $r = $doc->createElement( "channel" ); 
  $doc->appendChild( $r ); 

  foreach( $channel as $item ) 
  { 
  $b = $doc->createElement( "item" ); 

  $title = $doc->createElement( "title" ); 
  $title->appendChild( 
  $doc->createTextNode( $item['title'] ) 
  ); 
  $b->appendChild( $title ); 

  $content = $doc->createElement( "media:content" ); 
  $content->appendChild( 
  $doc->createTextNode( $item['content'] ) 
  ); 
  $b->appendChild( $content ); 

  $duration = $doc->createElement( "jwplayer:duration" ); 
  $duration->appendChild( 
  $doc->createTextNode( $item['duration'] ) 
  ); 
  $b->appendChild( $duration ); 

  $r->appendChild( $b ); 
  } 

  echo $doc->saveHTML(); 
  $doc->save("write.xml") 
  ?>

Any ideas? I'm a newbie in PHP/XML, sorry :/

2 Answers 2

1

This line: <?xml version="1.0"?> is called XML Declaration and it is optional. So whether that line is there or not should not make any difference and pose any problems as long as you use valid XML.

As RSS is based on XML, you do not need to worry about that line being there.

I hope this clarifies this part of your question.

And as Q&A normally works best with one question each, here are those other two:

Sign up to request clarification or add additional context in comments.

Comments

0

It's necessary to put a header before the php code in the xml to inform jwplayer what's being loaded.

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.