如何通过XML文件使用PHP进行搜索并显示结果?

问题描述:

I am trying to build a very simple price comparison script.

Until now, I wrote a code that gets some product xml feeds from shops and with the help of XSLT I create a single-global xml of all those input XMLs. I use the XSLT because the shops have different names for elements.

Now I want to take it one step further and I want to create a search form that will display me the products let's say I have the term "laptop".

I know how to create a form, but I need a coding guidance to understand how to make it to search in my XML file (products.xml) and display let's say the

Thank you

我正在尝试构建一个非常简单的价格比较脚本。 p>

到目前为止,我编写了一个代码,从商店获取一些产品xml提要,并在XSLT的帮助下,我创建了所有这些输入XML的单一全局xml。 我使用XSLT,因为商店有不同的元素名称。 p>

现在我想更进一步,我想创建一个搜索表单,向我显示产品让我说我 有一个术语“笔记本电脑”。 p>

我知道如何创建一个表单,但我需要一个编码指南来了解如何使它在我的XML文件(products.xml)中进行搜索 显示让我们说 p>

谢谢 p> div>

You might want to check out http://php.net/manual/en/class.xmlreader.php

Using that it is pretty easy to navigate through an XML file and grab all the info you need.

EDIT: On second thought, http://php.net/manual/en/book.simplexml.php is a MUCH simpler way to achieve what you're trying to do. Hence the name, I guess ;)

You can use SimpleXML library to parse your xml file. In my opinion SimpleXML is easier to use than xmlreader. Though SimpleXML is introduced on php5.