Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
比较php中的两个xml文件_Php_Xml_Xml Parsing - Fatal编程技术网

比较php中的两个xml文件

比较php中的两个xml文件,php,xml,xml-parsing,Php,Xml,Xml Parsing,我想比较PHP中的两个xml文件,一个文件包含客户数据(customerdata.xml),另一个文件包含用于过滤客户数据的规则(rule.xml),并希望获得过滤后的客户数据(result.xml) customerdata.xml <customerdata> <firstname>allen</firstname> <lastname>peter</lastname> <age>21</age> <c

我想比较PHP中的两个xml文件,一个文件包含客户数据(customerdata.xml),另一个文件包含用于过滤客户数据的规则(rule.xml),并希望获得过滤后的客户数据(result.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>

艾伦
彼得
21
NL
阿尔比
杰瑞
31
在里面
托马斯
阿尔弗雷德
28
NL
阿杰
拉加夫
21
在里面
这是客户详细信息的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>

阿尔比
杰瑞
31
在里面
阿杰
拉加夫
21
在里面
我不知道如何过滤,请帮助我。

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


我建议尝试与SQL查询类似但对XML文件有效的方法。

在您的规则中,您在哪里定义了应用规则的标记?我假设您将其应用于“country”,但如果以大写形式输入,它也可以是名字“INA”。这不是让人们为您编写代码的地方。如果你告诉我们你有什么,我们可以为你指出正确的方向,或者帮助你解决你遇到的问题。。。