One xml namespace equals one and only one schema file?

后端 未结 1 1834
情歌与酒
情歌与酒 2020-12-15 04:50

...or Why do these files validate in Visual Studio 2010 but not with xmllint1?

I\'m currently working against a publish

相关标签:
1条回答
  • 2020-12-15 05:41

    The crux of the problem here is what does it mean when you have two different <import> elements, when both of them refer to the same namespace.

    It helps to clarify the meaning when you consider that the schemaLocation attribute of <import> is entirely optional. When you leave it out, you're just saying "I want to import schema of namespace XYZ into this schema". The schemaLocation is just a hint as to where to find the definition of that other schema.

    The precise meaning of <import> is a bit fuzzy when you read the W3C spec, possibly deliberately so. As a result, interpretations vary.

    Some XML processors tolerate multiple <import> for the same namespace, and essentially amalgamate all of the schemaLocation into a single target.

    Other processors are stricter, and decide that only one <import> per target namespace is valid. I think this is more correct, when you consider that schemaLocation is optional.

    In addition to the VS and xmllint examples you gave, Xerces-J is also super-strict, and ignores subsequent <import> for the same target namespace, giving much the same error as xmllint does. XML Spy, on the other hand, is much more permissive (but then, XML Spy's validation is notoriously flaky)

    To be safe, you should not have these multiple imports. A given namespace should have a single "master" document, which in turn has an <include> for each sub-document. This master is often highly artificial, acting only as a container. for these sub-documents.

    From what I've seen, this generally consists of "best practise" for XML Schema when it comes to maximum tool compatibility, but some will argue that it's a hack that takes away from elegant schema design.

    Meh.

    0 讨论(0)
提交回复
热议问题