您好我有一个包含大约 12,000 条记录的 xml 文件。我编写了代码,它工作正常,只需要一段时间来解析 xml 文件并返回内容。有什么方法可以加快这个过程吗?
我的代码:
<?php
$dom = new DOMDocument();
$dom->load('comics.xml');
foreach ($dom->getElementsByTagName('record') as $entry)
{
$title = $entry->getElementsByTagName('title')->item(0)->textContent;
echo $title;
}
?>
XML 文件(其中只有 1 个演示无法链接所有内容,哈哈):
<?xml version='1.0' encoding='utf-8'?>
<calibredb>
<record>
<id>1</id>
<uuid>991639a0-7cf6-4a34-a863-4aab8ac2921d</uuid>
<publisher>Marvel Comics</publisher>
<size>6109716</size>
<title sort="Iron Man v1 101">Iron Man v1 101</title>
<authors sort="Unknown">
<author>Unknown</author>
</authors>
<timestamp>2012-04-15T18:49:22-07:00</timestamp>
<pubdate>2012-04-15T18:49:22-07:00</pubdate>
<cover>M:/Comics/Unknown/Iron Man v1 101 (1)/cover.jpg</cover>
<formats>
<format>M:/Comics/Unknown/Iron Man v1 101 (1)/Iron Man v1 101 - Unknown.zip</format>
</formats>
</record>
</calibredb>