/** * The collation strategy should to collate all child nodes before callback * * @param Node $node * @param \XMLReader $xmlReader * * @return Node The node with children collated will be passed to the callback */ protected function processNode(Node $node, \XMLReader $xmlReader) { $node = parent::processNode($node, $xmlReader); $children = []; if (!$xmlReader->isEmptyElement) { $scanner = new NodeStrategyTraversal(); $scanner->addNodeHandler('*', new self(function ($node) use(&$children) { $children[] = $node; })); $scanner->parse($xmlReader, $this->startDepth); } $node->children = $children; return $node; }
public function parse(\XMLReader $xmlReader, $startingDepth = 0, $parseOne = false) { parent::parse($xmlReader, $startingDepth, $parseOne); // Keep scanning elements while we have elements to scan and we are still within our scope // namely that the depth is greater than our own depth. while ($xmlReader->read() && $xmlReader->depth > $startingDepth) { if ($xmlReader->nodeType == \XMLReader::ELEMENT) { foreach ($this->nodeHandlers as $name => $strategy) { if ($name == "*" || $name == $xmlReader->name) { $strategy->parse($xmlReader, $xmlReader->depth); if ($parseOne) { return true; } } } } } return false; }