xml学习笔记--xml的应用生成一个vlc播放列表




      vlc播放列表用的是xspf格式,其官方网址为:http://www.xspf.org/。其实,其也为一种xml格式。这样其实穿件播放列表的过程就是创建xml文档的过程,生成完xml后最后保存文件时直接保存成xspf格式即可用vlc打开就可以观看播放列表的视频、音频等等。

其工作流程就是,先把location和title一条一条的存入数据库,然后生成对应格式的xspf文件。

因为数据库都是在我的本地电脑上运行的。所以数据库的密码用户名什么的都需要修改。

存入到数据库(下载源码

<?php
   //if(isset($_POST["sub"])&& !empty($_POST["location"]) &&!empty($_POST["tvTitle"]))
   //wu zuo yong
   if(isset($_POST["sub"]))
   {
       $h=mysql_connect("127.0.0.1","root","123a123a"or die(mysql_error());
       mysql_select_db("yz",$hor die(mysql_error());

       for ($i=0$i < 10$i++{
           # code...
           if(empty($_POST["location"][$i])) continue;
           $insert='insert into track(location,tvTitle) values("'.$_POST["location"][$i].'","'.$_POST["tvTitle"][$i].'")';
           mysql_query($insertor die(mysql_error());
       }
         

       mysql_free_result($r);
       mysql_close($h);

   }
   //var_dump($_POST["location"]);
?>
<html>
   <head>
       <meta charset="utf-8">
       <title>cha ru</title>
   </head>
   <body>
       <form action="" method="post" >
       <?php
           for ($i=0$i < 10$i++{
               echo '<p>location:<input type="text" name="location[]"> tvTitle: <input type="text" name="tvTitle[]" "></p>';
           }
       ?>
           <p> <input type="submit" name="sub"> </p>
       </form>
   </body>
</html>


生成xspf(下载源码)


HTML+PHP语言: xml学习笔记
<?php
 
   header("Content-Type:text/xml;charset:utf-8");

   $xspf = new DOMdocument("1.0","utf-8");

   function creEle(&$parent,$eleName="")
   {
       global $xspf;
       // because the key word gloabal $xspf i worng a long time;
       $tem = $xspf->createElement($eleName);
       $parent->appendChild($tem);
       return 0;
   }

   function creAttr(&$parent,$eleName="",$value="")
   {
       global $xspf;
       $tem = $xspf->createAttribute($eleName);
       $tem->value = $value;
       $parent->appendChild($tem);
       return 0;
   }

   function creTextNode(&$parent,$value="")
   {
       global $xspf;
       $tem =$xspf->createTextNode($value);
       $parent->appendChild($tem);
       return 0;
   }

   //playlist node generate
   $playlist = $xspf->createElement("playlist");
 
   $pl_attr_xlmns = $xspf->createAttribute("xmlns");
   $pl_attr_xlmns->value = "http://xspf.org/ns/0/";
   $playlist->appendChild($pl_attr_xlmns);

   $pl_attr_version = $xspf->createAttribute("version");
   $pl_attr_version->value = "1";
   $playlist->appendChild($pl_attr_version);
 

   //title
   creEle(&$playlist,"title");
   creTextNode($playlist->lastChild,"TvList");
   // <creator>
 
   creEle(&$playlist,"creator");
   creTextNode($playlist->lastChild,"soul11201");
 
   //<info>http://soul11201.eu.nu</info>
   creEle(&$playlist,'info');
   creTextNode($playlist->lastChild,'http://soul11201.eu.nu');
 
   //trackList
   creEle(&$playlist,"trackList");
   $trackList = $playlist->lastChild;


 
   //////////////////////////////////////////////////////////////////////////////
   //mysql;

   $handle=mysql_connect("127.0.0.1","root","123a123a") or die(mysql_error());
   mysql_select_db("yz",$handle) or die(mysql_error());
 
   $select = "select * from track";
   $result = mysql_query($select);
   while($row= mysql_fetch_row($result))
   {
       //echo $row[2].'<br/>';

       //var_dump($row[2]);


       //track
       creEle($trackList,'track');
       $currentTrack = $trackList->lastChild;
       //locatiion
       creEle($currentTrack,'location');
       creTextNode($currentTrack->lastChild,$row[2]);
       creEle($currentTrack,'title');
       creTextNode($currentTrack->lastChild,$row[3]);
       ///////////////////////////


   }
   mysql_free_result($result);
   mysql_close($handle);
   //debug result

   //////////////////////////////////////////////////////////////////////////



   $xspf->appendChild($playlist);
   $xspf->save("yz.xspf");
   echo $xspf->saveXML($playlist);

?>



xml学习笔记--xml的应用生成一个vlc播放列表
http://blog.soul11201.com/2014/02/12/xml-xmlvlc/
作者
soul11201
发布于
2014年2月12日
许可协议