Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Preserve XML processing instructions #3

Closed
infotexture opened this issue Nov 13, 2019 · 8 comments · Fixed by #6
Closed

Preserve XML processing instructions #3

infotexture opened this issue Nov 13, 2019 · 8 comments · Fixed by #6

Comments

@infotexture
Copy link
Contributor

infotexture commented Nov 13, 2019

This plug-in currently preserves the optional XML declaration on the first line of XML files, but strips any subsequent processing instructions from the rest of the file.

For example, in many XML workflows, <?xml-model … ?> processing instructions are used to provide validation support via schema languages like RELAX NG, W3C XML Schema, DTD and Schematron.

<?xml version="1.0" encoding="UTF-8"?>
<?xml-model href="project.rnc" type="application/relax-ng-compact-syntax"?>
<foo />

For more information, see http://www.w3.org/TR/xml-model/ and http://xml-model.info.

Other use cases may depend heavily on other (proprietary) processing instructions, so it would be best to provide an option to handle all processing instructions, regardless of their content.

If the project prefers to remove processing instructions by default, at least consider adding a configuration option that would allow users to preserve them if necessary.

@infotexture
Copy link
Contributor Author

infotexture commented Nov 15, 2019

best to provide an option to handle all processing instructions, regardless of their content

Looks like the implementation in #6 only handles XML declarations and <?xml-model?> processing instructions by searching for ?xml or ?xml-model on Line 10 of src/parse.js, but it still strips all other processing instructions from the rest of the file.

Per the spec, regular processing instructions don't begin with ?xml but might contain other combinations of characters, like <?pagebreak?> or

<?oxy_delete author="Bob" timestamp="20191115T162115+0100" content="deleted words"?>

Since processing instructions are currently deleted, I suggest you re-open this issue.

It looks like the current code also inserts an extra space before the closing ?> of XML declarations like it does before the closing slash in empty elements.

While this is not exactly wrong, I think it's less common practice in most cases — but this is perhaps better treated as a separate issue. (UPDATE: now governed by xmlSelfClosingSpace. See #11.)

@infotexture
Copy link
Contributor Author

@kddeisz See previous comment:

Since processing instructions are currently deleted, I suggest you re-open this issue.

@bd82
Copy link

bd82 commented Jan 27, 2020

The processing Instructions should appear in the Parser's output
So I guess it is just a matter of "printing" them.

@bd82
Copy link

bd82 commented Jan 27, 2020

Although they are consumed as a single large token:

We should probably properly parse their parts to allow for "pretty" re-printing.
Please open an issue in xml-tools repo if that is the case...

@kddnewton
Copy link
Member

@infotexture this is working on v0.5.0. Are you having trouble with it?

@infotexture
Copy link
Contributor Author

@kddeisz Yes, even in 0.6.0, processing instructions that don't start with ?xml are still being dropped as described in my previous comment. Tried with the sample PIs provided there:

<?pagebreak?>
<?oxy_delete author="Bob" timestamp="20191115T162115+0100" content="deleted words"?>

@kddnewton
Copy link
Member

Ahh I didn't understand until I continued messing with it that you meant processing instructions inside of other elements as opposed to outside the root element. I've opened #50 to handle that.

@infotexture
Copy link
Contributor Author

Thanks, your changes in f38f070 for #50 did the trick. 🙇

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants