如何使用 simplexml_load_string 将多个 XML 文件加载到一个字符串中?
我想使用 simplexml_load_string 函数将三个 xml 文件加载到我的 php 文件中。
我怎样才能实现这个目标?
@Jan-Henk:
这是我在评论中写的内容:
这就是我目前所拥有的,它搜索员工 Jane 的一个 xml 文件:
$result = simplexml_load_file('employees1.xml');
echo "<strong>Matching employees with name 'Jane'</strong><br />";
$employees = $result->xpath('/employees/employee[name="Jane"]');
foreach($employees as $employee) {
echo "Found {$employee->name}<br />";
}
echo "<br />";
三个 xml 文件会是什么样子。然后不要像上面那样搜索员工 Jane。它应该搜索这三个文件是否有重复项。因此,如果一名员工在三个文件中的任何一个中被列出两次。它应该返回:“找到简”。
I have three xml files that I want to load into my php file with the simplexml_load_string function.
How can I achieve this?
@Jan-Henk:
Here is what I wrote on the comments:
This is what I have at the moment , it searches one xml file for the employee Jane:
$result = simplexml_load_file('employees1.xml');
echo "<strong>Matching employees with name 'Jane'</strong><br />";
$employees = $result->xpath('/employees/employee[name="Jane"]');
foreach($employees as $employee) {
echo "Found {$employee->name}<br />";
}
echo "<br />";
How would this look like with three xml files. And then instead of searching for employee Jane like above. It should search the three files for duplicates. So if an employee is listed two times in either of the three files. It should return: "Found Jane".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需分别加载所有 3 个文件:
如果您确实想使用 simplexml_load_string 而不是 simplexml_load_file,您可以执行以下操作:
回答问题中的编辑,该编辑仅适用于 Jane 名称:
Just load all 3 files separately:
If you really want to use simplexml_load_string instead of simplexml_load_file you can do:
Answer for the edit in your question, which only works for the name Jane: