Is there a "one schema rule" for XML?

I have an XML file with 14 schemas to validate. All schemas are standalone and don’t import each other, nor is there any sort of "super schema" that links all of them…

All the online / downloadable tools I could find ask me to upload my XML file and then provide ONE schema file.

I am just asking, from an XML standard point of view, am I understanding schemas wrong and they all can somehow be used with one file? Again, the different schemas governing my XML file are each specific to their namespace and no inheritance or reuse of other schemas inside schemas.

It’s just weird, that even a tool that costs $100 (XmlBluePrint) only lets you use one schema file for validation…

On the other hand, I know java can do:

Schema schema = schemaFactory.newSchema(new Source[] {             new StreamSource(new FileInputStream("main.xsd")),             new StreamSource(new FileInputStream("extension.xsd")),     }); 

But I am not so confident with Java, maybe I don’t understand something?

Add Comment
2 Answer(s)

You are correct on both accounts:

  1. There is no "one schema rule for XML" anywhere in the XML standard: You are allowed to validate an XML document with as many schemas as you’d like.

  2. There is little support by tools for specifying more than one schema for an XML document. Even the xsi:noNamespaceSchemaLocation and xsi:schemaLocation hints from the standard only directly support association with a single XSD and a single XSD per namespace, respectively.

Options include writing custom code or manually changing settings.


Answered on July 17, 2020.
Add Comment

Terminology: a schema document is a file in XSD syntax containing source declarations. A schema is a collection of schema components obtained by compiling one or more schema documents. If you combine two schemas, the result is a schema. So you’re only ever validating against one schema, but it may be derived from multiple schema documents, which may or may not be "linked" using xs:import/xs:include.

There certainly are tools and APIs that allow you to assemble a schema from multiple (non-linked) schema documents. For example, the Saxon command line interface allows it: see!schema-processing/commandline

But there may well be other tools that don’t allow it.

Add Comment

Your Answer

By posting your answer, you agree to the privacy policy and terms of service.