Heim  >  Artikel  >  Backend-Entwicklung  >  如何读取五十万个节点的xml文件?

如何读取五十万个节点的xml文件?

WBOY
WBOYOriginal
2016-06-06 20:35:41939Durchsuche

目前二级节点大概有十万个,每个二级节点下面还有四级节点;

我用php,echo出来,特别耗内存。

方法粗暴:

<code>$xml = simplexml_load_file('example.xml'); 

foreach($xml->Article as $ArticleInfo) 
{
    //读取;
}
</code>

主要是想把数据导入到mysql中;
请教有没有便捷的方法?

回复内容:

目前二级节点大概有十万个,每个二级节点下面还有四级节点;

我用php,echo出来,特别耗内存。

方法粗暴:

<code>$xml = simplexml_load_file('example.xml'); 

foreach($xml->Article as $ArticleInfo) 
{
    //读取;
}
</code>

主要是想把数据导入到mysql中;
请教有没有便捷的方法?

用 XML Parser 就可以。

通过xml_set_element_handler()xml_set_character_data_handler()设置处理方法,读取一段处理一段。具体请看文档。

PHP不熟,但是其它语言都是流式读取XML的方式,PHP应该也有。
查了一下,下面这篇文章好像是流式读取,你可以试试

如何使用PHP处理比较大的XML文件

Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn