2010-07-02 49 views
0

导出我有一个XML文件,文件名是file.xml 这是内容如何从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> 

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

感谢

回答

3

你可以去SimpleXML

你可能也想看看这个漂亮教程:

Introduction To SimpleXML With PHP

+1

这应该是最简单的解决方案! – 2010-07-02 19:22:43

+0

'foreach($ xml-> ITEMS-> Item as $ item){echo $ item-> PAD_URL; }' - 嗯,*神圣消失的评论蝙蝠侠!* – salathe 2010-07-02 19:50:13

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(); 

} 
+0

或'$ xml = new DOMDocument; $ XML->负载( 'file.xml'); ($ xml-> getElementsByTagName('PAD_URL')as $ pad){echo $ pad-> nodeValue; }' – salathe 2010-07-02 19:54:03