如何使用php读取文件中的多个xml内容
问题描述:
我正在处理这种 XML 序列文件,你能不能建议我解析一下:
I'm dealing with this kind of XML sequence file can you any one suggest me to parse this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE us-patent-grant SYSTEM "us-patent-grant-v42-2006-08-23.dtd" [ ]>
<name>ccccc</name>
<document-id>
<country>US</country>
<doc-number>D0629997</doc-number>
<kind>S1</kind>
<date>20110104</date>
</document-id>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE us-patent-grant SYSTEM "us-patent-grant-v42-2006-08-23.dtd" [ ]>
<name>dddd</name>
<document-id>
<country>US</country>
<doc-number>D0629998</doc-number>
<kind>S2</kind>
<date>20110104</date>
</document-id>
答
这不是有效的 XML 文件.它看起来像两个文件合二为一,但即使如此它也是无效的.假设这些是两个单独的文件,您可以先尝试整理"它们.假设 $xml 是一个包含 xml 内容的字符串:
That's not a valid XML file. It looks like two files in one, but even then it is invalid. Assuming those are two separate files, you could try "tidying" them first. Assuming $xml is a string containing the xml contents:
$xml = tidy_repair_string($xml, array(
'output-xml' => true,
'input-xml' => true
));
然后你可以在它上面使用 SimpleXml:
Then you could use SimpleXml on it:
$xml = new SimpleXmlElement($xml);