Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

The only reference to Processing Instructions I could find in the XML Schema 1.1 specification was in section 3.1.4:

The above definition means that comments and processing instructions, even in the midst of text, are ignored for all ·validation· purposes.

That seems to imply that processing instructions cannot be represented in XML Schema.

XML Schema only was designed to validate elements and attributes, and to a very limited extent, their content (enumerations, or data types).

There is no provision for checking the other node types, such as comment or processing instructions.

There are alternatives to XML Schema for validation. Schematron for example lets you check content.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top