在perl中串行处理XML数据

我想知道在Perl的情况下,哪些 XML解析器的人是最好的.我做了很多阅读,并尝试过XML :: LibXML和XML :: SAX.第一个用完了太多的内存,第二个内存似乎并没有那么快(即使关闭了纯Perl解析器).

我的需求是相当具体的.我通过Net :: SSH库收到最多50MB的最大响应.我想将这些数据传递给XML库,因为我收到它,以保持内存中的最小数据量.我需要然后在某些标签中查找数据,并做任何事情,在某些情况下,总结一堆值,在其他情况下,只需提取值并将其写入文件或其他任何内容.所以我需要一个可以连续工作的XML解析器,工作速度很快,并且使用最少的内存.我得到的数据是多达1024个字节的块,所以我想要像$myparser-> sendData($mynewData)这样做,然后在打开或关闭一个标签调用函数类似于XML :: SAX.

我不一定需要XPath或XSLT.

解决方法

你也可以用简单的老 XML::Parser,这几乎只是你要求的:

“This module provides ways to parse XML documents. It is built on top of XML::Parser::Expat,which is a lower level interface to James Clark’s expat library. Each call to one of the parsing methods creates a new instance of XML::Parser::Expat which is then used to parse the document. Expat options may be provided when the XML::Parser object is created. These options are then passed on to the Expat object on each parse call. They can also be given as extra arguments to the parse methods,in which case they override options given at XML::Parser creation time.”

“Expat is an event based parser. As the parser recognizes parts of the document (say the start or end tag for an XML element),then any handlers registered for that type of an event are called with suitable parameters.”

我已经用它来解析Wikipedia XML dumps,即使在压缩之后它们也是几GB的大小,并且发现它在这方面工作得很好.相比之下,一个50 MB的文件应该是一块蛋糕.

相关文章

1. 如何去重 #!/usr/bin/perl use strict; my %hash; while(...
最近写了一个perl脚本,实现的功能是将表格中其中两列的数据...
表的数据字典格式如下:如果手动写MySQL建表语句,确认麻烦,...
巡检类工作经常会出具日报,最近在原有日报的基础上又新增了...
在实际生产环境中,常常需要从后台日志中截取报文,报文的形...
最近写的一个perl程序,通过关键词匹配统计其出现的频率,让...