Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

.net - Is it an error to import the same XSD multiple times?

I have a schema (a) that imports another schema (z). Then I have yet another schema (b) that imports that same schema (z).

It happens so that XML document (d) conforming to schema (a) can also contain an optional element that conforms to schema (z).

In consequence, when (d) is validated in .NET, I'm having exception "The simpleType 'z:x' has already been declared."

But there is no exception in Oxygen.

I'd like to configure .net the way it does NOT throw this exception. Just to behave like Oxygen.

How?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The problem arises due to the XSD Recommendation allowing, but not requiring, conformant processors to ignore the import of an XSD from an already encountered namespace. .NET is re-importing, as it is allowed to do. Oxygen is ignoring re-imports, as it is allowed to do.

Both are operating in conformance to the XSD Recommendation. See the last note in 4.2.3 References to schema components across namespaces:

Note: The above is carefully worded so that multiple <import>ing of the same schema document will not constitute a violation of clause 2 of Schema Properties Correct (§3.15.6), but applications are allowed, indeed encouraged, to avoid <import>ing the same schema document more than once to forestall the necessity of establishing identity component by component. Given that the schemaLocation [attribute] is only a hint, it is open to applications to ignore all but the first <import> for a given namespace, regardless of the ·actual value· of schemaLocation, but such a strategy risks missing useful information when new schemaLocations are offered.

Fortunately, Oxygen is based on Xerces, which allows the user to control this behavior via

http://apache.org/xml/features/honour-all-schemaLocations

Unfortunately, the .NET XML/XSD processor is not based on Xerces, and I am unaware of any parallel configuration option in any .NET version. (I will happily update this answer if shown otherwise.)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...