【问题标题】:Compare two xml files in php比较php中的两个xml文件
【发布时间】:2012-10-23 10:36:14
【问题描述】:

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

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

【问题讨论】:

  • 您在规则的哪个位置定义了应用规则的标签?我假设您将其应用于“国家”,但如果以大写形式输入,它也可以是名字“INA”。
  • 这里不是让人们为您编写代码的地方。如果您向我们展示您拥有的东西,我们可以从那里为您指明正确的方向,或帮助您解决遇到的问题...

标签: php xml xml-parsing


【解决方案1】:

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

我建议尝试XQUERY,它的作用类似于 SQL 查询,但作用于 XML 文件。

【讨论】:

    猜你喜欢
    • 2023-03-15
    • 1970-01-01
    • 2018-11-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-30
    • 1970-01-01
    相关资源
    最近更新 更多