Add processing instruction callbacks - #10
Merged
xoofx merged 1 commit intoJul 13, 2026
Merged
Conversation
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Owner
|
Thanks! |
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.
Summary
TurboXml currently recognizes generic processing instructions (PIs) for well-formedness, but silently discards them. This prevents handler-based consumers from preserving unmodeled XML extension content when they need to capture and later reproduce it.
This PR adds a backward-compatible
IXmlReadHandler.OnProcessingInstructioncallback so consumers can opt in to handling generic PIs.API and behavior
targetis the PI target.datais the exact source text aftertargetand before?>, including any separator whitespace, tabs, and line endings.<?{target}{data}?>.OnXmlDeclaration; they are not reported as generic PIs.xml-like targets according to its existing validation rules.The callback follows the parser's existing
ReadOnlySpan<char>event model, avoiding string allocation in the parser API.Why this matters
Consumers that retain unknown or extension XML for later serialization can currently lose a PI during parsing even when they preserve the surrounding elements and attributes. Reporting the PI makes lossless capture and round-tripping possible without changing the default behavior for existing consumers.
Tests
Added regression coverage for:
Validation