0

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

客户数据.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)中包含的某些规则过滤这些详细信息

规则.xml

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

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

结果.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>

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

4

1 回答 1

0

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

我建议尝试XQUERY,它与 SQL 查询类似,但在 XML 文件上工作。

于 2012-10-23T10:42:08.270 回答