微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

在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的文件应该是一块蛋糕.

原文地址:https://www.jb51.cc/Perl/171456.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐