我正在尝试从文件夹中读取多个xml文件,并希望获取标记属性以供进一步处理。 到目前为止,我已尝试了许多可用的示例,但到目前为止没有运气。
下面是我的代码,任何帮助将不胜感激..!谢谢..!
foreach (glob("unzip_temp/other/newfolder/*.xml") as $filename) {
$xml_file = file_get_contents($filename, FILE_TEXT);
$xml = simplexml_load_file($xml_file);
foreach ($xml->tag1 as $fileinfo) {
$name = $fileinfo['Name'];
$language = $fileinfo['Language'];
$creator = $fileinfo['Creator'];
echo "<li> $name ,$language ,$creator";
}
下面的是我想要阅读的xml文件的一部分:
<?xml version="1.0" encoding="utf-16"?>
<tag1 xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" Name="Bethanien_Befunder_CTKolon" Language="other" Type="Simple" Creator="ADMINISTRATOR" IsMultiSelect="false" IsFloatingPickList="false" IsPhraseGenerated="false">
答案 0 :(得分:0)
我得到了解决方案:无论如何谢谢
$doc = new DOMDocument();
foreach (glob("unzip_temp/other/newfolder/*.xml") as $filename) {
$doc->load($filename);
$intros = $doc->getElementsByTagName("tag1");
foreach ($intros as $intro) {
echo "<br />";
$name = $intro->getAttribute('Name');
echo $name;
echo "<br />";
echo $intro->getAttribute('Creator');
echo "<br />";
echo $intro->getAttribute('Language');
echo "<hr />";
}
}