需要XML数据获取帮助


XML Data Fetch help need

我有一个用于项目工作的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;从标题中获取数据。它成功地返回了标题。

如何使用php从页面中的标记中获取数据?

使用php的simplexml函数。

加载:$xml = simplexml_load_string($xml);,如果您有字符串或$xml = simplexml_load_file($xmlFile);(如果您有一个文件)。

如果xml有效,您将获得一个SimpleXmlElement。检查以下链接:http://php.net/manual/en/class.simplexmlelement.php.在那里你会发现几个关于如何从中获取数据的功能

Btw。你真的想得到哪些数据?