dsfdsfdsfdsf1223 2011-06-21 06:42
浏览 46
已采纳

使用PHP进行XML解析

I have a .out file which has xml content like this.

<header stub>
    <article type="audio">
        <addedDate>2010-03-11 05:11:57</addedDate>
        <thumbnail>http://fgsdfff/4588/thumbnail_9.jpg</thumbnail>
        <asset="blarga.mp3" addedDate="2009-01-07 01:48:37">
            <size>3289048</size>
            <duration>206000</duration>
            <mime_type>audio/mpeg</mime_type>
        </asset>
    </article>
</footer stub>
  1. I have to add <?xml version="1.0"?> and </xml> at the start of the xml and at the end respectively.
  2. I have to replace <header stub> and </footer stub> with <channel> and </channel> tags respectively.
  3. You might have noticed the XML is not well formed in the <asset> tag. It has to be like <asset url="blarga.mp3" addedDate="2009-01-07 01:48:37">. How do I add the url attribute?
  4. In the thumbnail tag, i have to remove _9 from the jpg's name.

And finally, i have to convert the .out to .xml file.

Please help me with these

  • 写回答

2条回答 默认 最新

  • doujianzi8521 2011-06-21 06:57
    关注
    $content = file_get_content OR mysql_query;//"YOUR XML CONTENT FROM FILE OR MYSQL";
    $content = "<?xml version="1.0"?>" . $content . "</xml>";
    $content = str_replace("<header stub>", "<channel>", $content);
    $content = str_replace("</footer stub>", "</channel>", $content);
    $content = str_replace("<asset=", "<asset url=", $content);
    $content = str_replace("thumbnail_9.jpg", "thumbnail.jpg", $content);
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害