Skip to content

Instantly share code, notes, and snippets.

@m8rge m8rge/XMLReader.php
Created May 29, 2015

Embed
What would you like to do?
<?php
namespace console\components;
class XMLReader extends \XMLReader
{
/**
* @param string $nodeName
* @return $this
*/
public function readUntil($nodeName)
{
while (!($this->nodeType == XMLReader::ELEMENT && $this->name == $nodeName) && $this->read()) {
}
return $this;
}
/**
* @param string $nodeName
* @param callable $callback
* @return $this
*/
public function readAll($nodeName, $callback)
{
$this->read();
do {
if ($this->nodeType == XMLReader::ELEMENT && $this->name == $nodeName) {
call_user_func($callback);
}
} while ($this->next($nodeName));
return $this;
}
/**
* @inheritdoc
*/
public function open($URI, $encoding = null, $options = null)
{
if (is_null($options)) {
$options = LIBXML_NONET | LIBXML_NOBLANKS | LIBXML_NOERROR | LIBXML_NOWARNING;
}
return parent::open($URI, $encoding, $options);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.