本文介绍了XSD导入命名空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有两个xsd文件"first.xsd"和"second.xsd".

I have a two xsd files "first.xsd" and "second.xsd".

在second.xsd中,我想引用first.xsd中定义的元素(具有不同的命名空间).
我的second.xsd看起来像:

Inside second.xsd, I want to refer to an element defined in first.xsd (with different namespace).
My second.xsd looks like:

<xs:schema ... xmlns:schema1="http://www.schema.org/schema1" targetNamespace "http://www.schema.org/schema2   ...  >
<xs:import namespace = "http://www.schema.org/schema1" schemaLocation = "first.xsd" />

<xs:element name = "complex1">
<xs:complexType>
.........
<xs:element ref="schema1:name2"/>
.........
</xs:complexType>
</xs:element>

现在我要在first.xsd中包含并导入second.xsd因此,我在first.xsd中执行以下操作:

Now I want to include and import second.xsd inside first.xsdSo I do the following in first.xsd:

<xs:schema ... xmlns:schema2="http://www.schema.org/schema2" targetNamespace "http://www.schema.org/schema1  ... >
<xs:import namespace="http://www.schema.org/schema2" schemaLocation="second.xsd">
<xs:element name = "name1"/>
<xs:element name = "name2"/>
<xs:element name = "name3"/>

这是正确的方法,因为我无法成功验证架构.
是否由于包含一些循环名称空间而引起问题?
我正在使用Oxy xml开发人员来验证架构文件,验证时我的first.xsd表示:
E [Xerces] src-resolve:无法将名称解析为类型定义组件. (second.xsd)

Is this the right way to do since I not able to successfully validate the schema.
Is it a problem because of some cyclic namespace inclusion??
I'm using oxygen xml developer to validate the schema files and my first.xsd when validated says:
E[Xerces] src-resolve: Cannot resolve the name to a(n) type definition component. (second.xsd)

但是,如果我分别验证second.xsd文件,则它表示架构有效.

But if I validate the second.xsd file separately it says schema valid.

在我的实际情况下,我有一个非常复杂的场景,因此我将其简化为一个简单的示例,如上所示.
有人可以帮忙吗.

In my actual case I have a very complex scenario so I've boiled it down to a simple example as shown above.
Could someone please help.

推荐答案

具有这种循环依赖关系是完全有效的(尽管值得商bat).您的模式集未通过验证的原因不能是它;您将必须检查架构处理器生成的错误,并尝试了解每个错误.通常,最好的做法是从第一个错误消息开始.

It is perfectly valid (albeit debatable) to have these kind of circular dependencies; the reason why your schema set doesn't validate can't be it; you'll have to inspect the errors your schema processor generates and try to understand each one of them. It is generaly accepted that the best is to start with the first error message.

您的代码段无效,因为您引用的是未在 schema1 中列出的element2(在second.xsd中).这种事情不会通过验证,因此请专注于它们.

Your snippets are invalid since you're referencing an element2 (in second.xsd) that you didn't list in schema1. This is the kind of thing that won't pass validation, so focus on them.

如果您需要帮助以了解真正的问题所在,请首先使用实际的错误消息更新您的帖子.

If you need help with understanding what the real issue is, start by updating your post with the actual error message.

这篇关于XSD导入命名空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-18 21:07