比较php中的两个xml文件

时间:2012-10-23 10:36:15

标签: php xml xml-parsing

我想比较PHP中的两个xml文件,一个文件包含客户数据(customerdata.xml)另一个包含规则(rule.xml),用于过滤客户数据,并希望获得客户的过滤数据(结果。 XML)

customerdata.xml

<customerdata>
<firstname>allen</firstname>
<lastname>peter</lastname>
<age>21</age>
<country>NL</country>
<firstname>alby</firstname>
<lastname>jerry</lastname>
<age>31</age>
<country>IN</country>
<firstname>thomas</firstname>
<lastname>alfred</lastname>
<age>28</age>
<country>NL</country>
<firstname>ajay</firstname>
<lastname>raghav</lastname>
<age>21</age>
<country>IN</country>
</customerdata>

这是客户详细信息的xml文件。我想根据另一个xml文件(rule.xml)中包含的某些规则来过滤这些细节

rule.xml

<rule>
<ruleoperator>contains</ruleoperator>
<rulevalue>IN</rulevalue>
</rule>  

这是我的规则xml。过滤后我想得到xml(result.xml)

的结果

为result.xml

<result>
<firstname>alby</firstname>
<lastname>jerry</lastname>
<age>31</age>
<country>IN</country>
<firstname>ajay</firstname>
<lastname>raghav</lastname>
<age>21</age>
<country>IN</country>
<result>

我不知道如何过滤这个,请帮帮我。

1 个答案:

答案 0 :(得分:0)

这里不能简单地“比较”这两个XML文件。您希望将规则从第二个规则“应用”到第一个规则以生成第三个规则。 为此,您必须在第一步中阅读所有规则并分析第一个文件以进行匹配。

我建议尝试XQUERY,它的工作方式类似于SQL查询,但是在XML文件上。

相关问题