0

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)

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. I want to filter these details against some rule contains in another xml file(rule.xml)

rule.xml

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

this is my rule xml. After filtering I want to get result as 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.

Akhil
  • 21
  • 1
  • 6
  • Where in your rule do you define the tag on which the rule shall be applied? I assume you apply it to "country" but it could be also firstname "INA" if it was entered in upper case. – eX0du5 Oct 23 '12 at 10:39
  • 1
    This is not a place to have people write your code for you. If you show us whatr you have, we can point you in the right direction from there, or help you fix the problem you are encountering... – Jasper Oct 23 '12 at 10:39

1 Answers1

0

You cannot simply "compare" the two XML files here. 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.

Community
  • 1
  • 1
eX0du5
  • 896
  • 7
  • 16