Add support for Processing instructions#14
Open
Holzhaus wants to merge 5 commits intomckamey:masterfrom
Open
Conversation
Unfortunately, this introduces an ugly empty TextNode as parentElement, but it works for now.
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.
This adds support for Processing Instructions. These are defined in the XML 1.0 Specification as follows:
Rationale
The JsonML website states:
But to provide a truly lossless way to convert arbitrary XML to JsonML and back, IMHO they should be preserved:
As per Section 2.6 of the XML 1.0 Specification, passing PIs through to an application is a "MUST" requirement.
Accordingly, PIs are also preserved during XML Canonicalization (C14N), which is a way to normalize the physical appearance of an XML document while retaining its logic. The retention of PIs indicates that they are not insignificant (by contrast, comment support is optional and things like DTD or XML Declaration are lost during C14N).
JsonML grammar modifications
Thus, I added support for Processing Instructions:
Processing Instructions can't be mistaken for elements since
#x3F(= Question Mark [?]) is not a validNameStartChar(which means that atag-namecan't begin with a question mark):One sublety is that when a document contains one or more Processing Instructions as top-level constructs (besides the
documentElement), then the resulting JsonML text will have a top level element with an empty string astag-nameand anelement-listconsisting of the PIs and thedocumentElementin the correct order.This behaviour is consistent with the handling of fragments in JsonML.
Please have a look at the examples below and let me know what you think. Thanks in advance!
Examples
Here's a simple example:
The above XML document represented as JsonML:
[ "foo", [ "?a-single-pi", "with data" ] ]Here's a more complex example with has Processing Instructions at the document level:
The above file will map to:
[ "", [ "?some-pi", "and its data" ], "\n", [ "foo", "\n ", [ "?another-pi", "with data" ], "\n" ], "\n", [ "?third-pi", "" ] ]