2014-10-16 120 views
-1

我有一個XML文件爲我的項目幹活需要從XML文件。該文件讀取數據中包含類似以下內容:XML數據獲取幫助需要

<?xml version="1.0" encoding="utf-8"?> 
<rss xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:szgd="http://www.spotzot.com/gdfeed" xmlns:szbb="http://www.spotzot.com/bbfeed"> 
<channel> 
<item> 
<title>Service &amp; Maintenance under $50</title> 
<description>7 Items | Prestone, Campbell Hausfeld, Custom Accessories, Custom, KD Tools</description> 
<szgd:instore>Y</szgd:instore> 
</item> 
</channel> 
</rss> 

我使用$newtitle=$newxml->channel->item->title;獲取數據來自title.It成功返回標題。

如何使用php從我的頁面中的標記獲取數據?

+0

你問哪個標籤? – Khushboo 2014-10-16 11:07:18

+0

你是如何加載'$ newxml'的? – Peter 2014-10-16 11:42:29

+0

我剛剛解決it.with $ newxml-> channel-> item-> children('http://www.spotzot.com/gdfeed') - > instore。這裏children()中的鏈接是szgd的值,它定義在xml的頂部。 – 2014-10-16 12:29:07

回答

0

使用php的simplexml函數。

加載它: $xml = simplexml_load_string($xml);如果你有,如果你有一個文件中的字符串或 $xml = simplexml_load_file($xmlFile);

如果xml有效,您將獲得一個SimpleXmlElement。檢查以下鏈接:http://php.net/manual/en/class.simplexmlelement.php。在那裏你會發現幾個關於如何從中獲取數據的函數。

Btw。你真的想得到哪些數據?