suramon/ simple-xml-reader
SimpleXmlElement的力量,结合XmlReader的资源友好性
1.2.2
2017-06-26 13:36 UTC
Requires
- php: >=5.3
Requires (Dev)
- phpunit/phpunit: ~3
This package is not auto-updated.
Last update: 2024-09-14 14:50:25 UTC
README
PHP XML Pull解析器XMLReader的接口,增加了超级简化的xpath功能。这对于读取大型xml文件来说非常理想,因为它不需要其他xml库(如SImpleXMLElement)的内存成本。
示例
源代码: https://github.com/SuRaMoN/simplexmlreader/blob/master/examples/simple-example.php
$xml = SimpleXmlReader::openFromString(' <root> <animal type="cat"> <hastail>yes</hastail> </animal> <animal type="dog"> <hastail>yes</hastail> </animal> <animal type="kakariki"> <hastail>no</hastail> </animal> </root> '); foreach($xml->path('root/animal') as $animal) { // $animal is of type SimpleXMLElelent // only the current iterated $animal is in memory, so huge xml files can be read, without much memory consumption echo "A {$animal->attributes()->type} has a tail? {$animal->hastail}!\n"; }