dongzhucha3999 2011-10-31 10:18
浏览 42

在多个xml文件上查找重复项

I got this code to search for a duplicate (of the employee Jane) on my two XML files:

<?php
$files = array('employee1.xml', 'employee2.xml');
$xpathQuery = '/employees/employee[name="Jane"]';
$count = 0;

foreach ($files as $file) {
$xml = simplexml_load_file($file);
$result = $xml->xpath($xpathQuery);

if (count($result) > 0) {
    $count++;
}
}

if ($count > 1) {
echo "Duplicates for Jane";
} else {
echo "No duplicates for Jane";
}
?>

Instead of searching for duplicates of the employee Jane like above, I would like the script to search for all duplicates on the two XML files. This would require extracting each value from the two XML files and using the loop above it should search if a value exist on both XML files. If the same name exist on both employee1.xml and employee2.xml, the results of this would be added to a third XML file called duplicates.xml

Is this possible? Thanks in advance

  • 写回答

1条回答 默认 最新

  • dthdlv9777 2011-10-31 10:33
    关注

    If your xml files are not too large, try to convert you xml files into arrays and then use php function : array_intersect() http://www.php.net/manual/en/function.array-intersect.php

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度