简体   繁体   English

比较PHP中的两个xml文件

[英]Compare two xml files in php

I want to compare two xml files in PHP, one file contains customers data(customerdata.xml) another contains rule(rule.xml) which is used to filter customer data, and want to get filtered data of customers(result.xml) 我想比较PHP中的两个xml文件,一个文件包含客户数据(customerdata.xml),另一个文件包含用于过滤客户数据的rule(rule.xml),并想要获取客户的过滤数据(result.xml)

customerdata.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>

this is the xml file of customer details. 这是客户详细信息的xml文件。 I want to filter these details against some rule contains in another xml file(rule.xml) 我想针对包含在另一个xml文件(rule.xml)中的某些规则过滤这些详细信息

rule.xml rule.xml

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

this is my rule xml. 这是我的规则xml。 After filtering I want to get result as xml(result.xml) 过滤后,我想获得结果为xml(result.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>

I dont know how to filter this, please help me. 我不知道该如何过滤,请帮助我。

You cannot simply "compare" the two XML files here. 您不能在这里简单地“比较”两个XML文件。 You want to "apply" rules from the second one to the first one to generate a third one. 您要“应用”从第二个规则到第一个规则以生成第三个规则。 For this, you will have to read all your rules in a first step and analyze the first file for matches. 为此,您将必须首先阅读所有规则,并分析第一个文件中的匹配项。

I recommend to try XQUERY which works similar like SQL queries but on XML files. 我建议尝试使用XQUERY ,它的工作方式类似于SQL查询,但适用于XML文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM