5

I have an XSD package composed of two XSD files: let's say A.xsd and B.xsd. The schema A imports (not includes) the B schema. They have different namespaces.

I need to use those schema in a system that doesn't work well with xsd:imports.

Is it possible to flatten an XSD package in one and only one XSD file or is one XSD file per namespace the absolute minimum?

4

2 回答 2

2

Each xs:schema element contains declarations for just one target namespace. But nothing in the spec says that xs:schema has to be the root element of the XML document. In theory, therefore, you could just wrap both schema elements in a wrapper file; in practice, not all XSD validators will be happy with that as input.

[Later addition: since it seems to be a contentious point, perhaps I should say explicitly that I'm assuming that by "one XSD file" you mean one XML document, contained in a single file, containing the XSD. If you mean something else, please explain.]

You don't say what kind of problems you're having with imports, but one thing that may be worth trying is to remove the schema location information from the xs:import element in A.xsd (so the import just names the namespace involved, not the location of the schema document), and pass both A.xsd and B.xsd to the processor as run-time parameters. (Most though not all XSD processors allow you to specify at invocation time some schema documents for them to read. The order of the arguments can matter, so if it doesn't work the first time, try reversing the order.)

于 2012-09-21T00:21:31.117 回答
1

No, it is not possible. You can only target one namespace per XSD. If anything, there's only one root xs:schema per XSD, with only one attribute (which is not a list) called targetNamespace.

于 2012-09-20T14:54:41.890 回答