Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Processing instruction validation in XML schema

Reasonably simple one I suppose, I just can't find anything definitive (besides the fact that there is a lack of anything definitive)

Is there any way to incorporate into a schema, the requirement of a processing instruction node at a place in the document, also perhaps validating the processing instruction target?

For instance:

<node>
    <?my-instruction data ?>
</node>

Would validate, whereas:

<node></node>

Would not?

And, better yet:

<node>
    <?my-other-instruction data ?>
</node>

Would not either (given I could supply a required target of my-instruction)

As mentioned, I can't find anything definitive (or at all for that matter) on the topic, so I'm left to assume this is something not supported. Others have mentioned that PIs are intended for "out-of-band" data and processing instructions, so it appears sensible that their inclusion would not be required in validation. Would be nice though.

like image 673
Dan Lugg Avatar asked Jul 12 '26 22:07

Dan Lugg


1 Answers

XSD completely ignores processing instructions in the instance document.

I'm not sure why you had difficulty finding this. Searching the spec for "processing instruction" gives one hit, which is the sentence in 3.1.4 that says "The above definition means that comments and processing instructions, even in the midst of text, are ignored for all ·validation· purposes."

In fact in XSD 1.1 we've had some debate about whether comments and processing instructions should be visible to assertions. The final decision is that by default they aren't visible, but processors can provide a switch to make them visible. In Saxon 9.4 you can set this switch using --assertionsCanSeeComments:on on the command line. With this switch set, you can write assertions in the schema that test for the presence or absence of processing instructions - but you can't incorporate them in the grammar of a complex type, which makes it tricky to constrain exactly where they must appear.

like image 155
Michael Kay Avatar answered Jul 18 '26 20:07

Michael Kay



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!