Repository navigation
#258 - Add XmlStreamReaderTask - #260
Merged
Merged
Conversation
… file element by element with \XMLReader (constant memory), outputting each element named node_name as a \DOMElement in its own \DOMDocument, ready for XpathEvaluatorTransformer. Add documentation and tests. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Merged
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #258.
New iterable task
CleverAge\ProcessBundle\Task\File\Xml\XmlStreamReaderTask, reading an XML file element by element with\XMLReader: memory stays constant whatever the file size, unlikeXmlReaderTaskwhich loads the whole file in a\DOMDocument(kept unchanged).node_name(string, required): qualified name of the elements to iterate on (e.g.product,g:item);file_path(string|null, defaultnull): whennull, the path is read from the input (likeJsonStreamReaderTask).\XMLReader::expand()as the root\DOMElementof its own\DOMDocument, so it can be passed directly toXpathEvaluatorTransformerwith relative queries (@sku,name/text()). Namespaces declared on ancestors are copied, so prefixed queries (g:price/text()) work.execute()(next()only tells whether the file is still open), so that XML errors are thrown inexecute()and handled by the taskerror_strategy. Invalid XML (including an empty file) throws an\UnexpectedValueExceptionwith the libxml messages (line/column), asXmlReaderTask; warnings are tolerated. A missing/unreadable file or no file path throws an\UnexpectedValueException.finalize(), so that the task can read it again on its next input.Requires the
xmlreaderextension (enabled by default, likedom); it is documented but not added tocomposer.jsonrequire, to avoid changing the requirements in a minor version.Tests:
XmlStreamReaderTaskTest(17 cases, including xpath evaluation throughXpathEvaluatorTransformer). PHPStan, PHPUnit (897 tests), PHP-CS-Fixer and Rector pass. Demonstrated bydemo.file.xml_stream_readerin process-bundle-demo.Requirements
Breaking changes
None: new task.
🤖 Generated with Claude Code