duanpai6581 2009-07-14 08:31
浏览 109
已采纳

如何将xml文件存储到mysql数据库并检索它?

I have generated a XML file automatically from the below code.

if (isset($_POST["song"])&& $_POST['song'] != "") {
    $song = $_POST["song"];
} else {
    $song = array();
}
$dom = new DOMDocument("1.0");
// display document in browser as plain text 
// for readability purposes

// create root element
$root = $dom->createElement("playlist");
$dom->appendChild($root);
$root->setAttribute('version', "1");
$root->setAttribute('xmlns', "http://xspf.org/ns/0/");
$rootnext = $dom->createElement("trackList");
$root->appendChild($rootnext);
foreach ($song as $counter) {
    $tokens = ",";
    $tokenized = strtok($counter, $tokens);
    // create child element
    $song = $dom->createElement("track");
    $rootnext->appendChild($song);
    $song1 = $dom->createElement("creator");
    $song->appendChild($song1);
    $text = $dom->createTextNode("www.musicking.in");
    $song1->appendChild($text); 
    $song1 = $dom->createElement("title");
    $song->appendChild($song1);
    // create text node
    $text = $dom->createTextNode($tokenized);
    $song1->appendChild($text); 
    $tokenized = strtok($tokens);
    $song1 = $dom->createElement("location");
    $song->appendChild($song1);
    $text = $dom->createTextNode($tokenized);
    $song1->appendChild($text); 
}
$dom->save("playlist.xml");

Actually after generating XML file it’s storing in the root directory.

Can you please tell me how to store the generated XML file into MySQL database?

After generating XML file I have to call that file. I am using below code to call:

<object data="musicplayer.swf?autostart=true&playlist=playlist.xml" type="application/x-shockwave-flash" width="400" height="300">
    <param name="movie" value="musicplayer.swf?autostart=true&playlist=playlist.xml"/>
</object>

Please tell me how to store and retrieve this playlist.xml file from mysql database?

  • 写回答

4条回答 默认 最新

  • douchongzhang9267 2009-07-14 08:40
    关注

    Use DOMDocument::saveXML() to get a string representation of your xml file and insert this string into an approrpiate column in your database. Depending on the size fo your data use a column of type TINYBLOB (2^8 bytes), BLOB (2^16 bytes), MEDIUMBLOB (2^24 bytes) or LONGBLOB (2^32 bytes) (if using MySQL or an appropriate data type in the RDBMS of your choice).

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度