如何从xml导出

时间:2010-07-02 19:19:52

标签: php xml

我有一个xml文件名是file.xml 这是内容

<PAD_INFO>
    <ITEMS>
        <Item>
            <PAD_URL>http://www.instant-navigator.com/instantn_pad.xml</PAD_URL>
            <Antivirus_Report_URL>http://instantnavigator-for-onenote.extramind-systems.qarchive.org/antivirusreport.html</Antivirus_Report_URL>
            <Last_Checking_Date>2010-06-28 05:09:18</Last_Checking_Date>
        </Item>
        <Item>
            <PAD_URL>http://www.mishelpers.com/network_monitor/netmonpro.xml</PAD_URL>
            <Antivirus_Report_URL>http://alchemy-network-monitor-pro.m-i-s-helpers.qarchive.org/antivirusreport.html</Antivirus_Report_URL>
            <Last_Checking_Date>2010-06-03 08:00:43</Last_Checking_Date>
        </Item>
        <Item>
            <PAD_URL>http://www.pdacraft.com/pad/pdacraft_paint_pad.xml</PAD_URL>
            <Antivirus_Report_URL>http://pdacraft-paint.pdacraft.qarchive.org/antivirusreport.html</Antivirus_Report_URL>
            <Last_Checking_Date>2010-06-05 01:34:11</Last_Checking_Date>
        </Item>
       </ITEMS>

</PAD_INFO>

请帮我从pad_url标签导出所有文件.xml 使用php

由于

2 个答案:

答案 0 :(得分:3)

你可以去SimpleXML

您可能还希望看到这个很好的教程:

Introduction To SimpleXML With PHP

答案 1 :(得分:1)

正如SaC所说...... SimpleXml可能是最简单的答案。

// assume $xmlstring is the xml you posted

$xml = new SimpleXmlElement($xmlstring);
$urls = $xml->xpath('//PAD_URL');

foreach($urls as $url)
{
  // when used in a string contect $url will be the text value
  echo $url;

  // however its still really the object so for example if you needed te attributes
  $attributes = $url->attributes();

}