gh-63102: Add XMLPullTarget and XMLPullParser.expand() - #157439
Open
serhiy-storchaka wants to merge 2 commits into
Open
gh-63102: Add XMLPullTarget and XMLPullParser.expand()#157439serhiy-storchaka wants to merge 2 commits into
serhiy-storchaka wants to merge 2 commits into
Conversation
XMLPullTarget is a parser target for XMLPullParser and iterparse() which reports elements without building a tree. The reported object is an Element with the tag, the attributes and, for the "end" event, the text, but without children: they are reported as their own events. Nothing is kept, so a document of any size can be parsed with a constant amount of memory, like with xml.dom.pulldom, but much faster. XMLPullParser.expand() builds the subtree of a reported element from the events which are already read from the parser, like expandNode() in pulldom. The iterator returned by iterparse() has the same method which reads more data if needed.
Documentation build overview
|
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.
XMLPullTargetis a parser target forXMLPullParseranditerparse()which reports elements without building a tree.start()returns a newElementwith the tag and the attributes,end()returns the same object with its text, but the children are never attached: they are reported as their own events. Nothing is kept, so a document of any size can be parsed with a constant amount of memory, like withxml.dom.pulldom, but much faster (on a 500 000-row document: 0.28 s and 386 KiB, versus 2.2 s and 10 MiB for pulldom, and 1.7 MiB forTreeBuilderwith theclear()idiom).XMLPullParser.expand(element)is the counterpart of pulldom'sexpandNode(): it builds the subtree of a reported element from the events which are already read from the parser, and returns it.ValueErroris raised if the element is not complete yet. The iterator returned byiterparse()has the same method, which reads more data itself.Follow-up of #156888.