2

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?

kjhughes
  • 106,133
  • 27
  • 181
  • 240
DraxDomax
  • 1,008
  • 1
  • 9
  • 28
  • You do not need any linking. when a schema is checked every prefix (or default prefix) is validated against the URL schema. The include is schema is only needed if a XML file reference a URL schema and the tags in the XML file are not in the URL. So if the XML has Prefix ABC with URL XYZ and XML has child of ABC which is DEF. Then if schema XYZ do not have prefix DEF then an INCLUDE is needed to reference a different schema that contains DEF. – jdweng Jun 30 '20 at 09:38
  • ok, but how can the tools validate a schema that I am not supplying? If the XML has 2 schemas and I am supplying just one for validation, I can actually see the tool complaining about missing element declaration – DraxDomax Jun 30 '20 at 10:51
  • Why do you have to supply a tool for validating an xml when the schema is in the xml file? This sounds more like a tool issue. – jdweng Jun 30 '20 at 12:58
  • (1) what makes you think the schema is in the XML file? (2) Just the fact a schema exists in the XML (if it did, which it isn't), doesn't mean the XML needs not to be validated! – DraxDomax Jun 30 '20 at 14:45
  • The prefix must have a namespace (otherwise you will get an error) and the namespace is used for validation. The schema attribute is ignored and is just additional info in the xml. – jdweng Jun 30 '20 at 14:48
  • Sorry I don't see how what you are trying to say relates to my question at all. Thanks for your input! – DraxDomax Jun 30 '20 at 14:55

2 Answers2

1

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.

Related

kjhughes
  • 106,133
  • 27
  • 181
  • 240
1

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 http://www.saxonica.com/documentation/index.html#!schema-processing/commandline

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

Michael Kay
  • 156,231
  • 11
  • 92
  • 164
  • Yes! They do mention this in the tutorials but it's easy (for me) to miss the semantics, that when they say "schema document", they mean a component of the schema. I think a lot of people miss that too and call each schema document a schema. Thanks! – DraxDomax Jun 30 '20 at 17:14
  • 1
    Yes, it's definitely an area where there's a lot of confusion caused by widepsread use of incorrect terminology (rather like the habit of referring to elements as tags). – Michael Kay Jun 30 '20 at 20:55