XSD:如何从另一个 XSD 导入数据类型?
我的 XSD 开头如下:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:no="http://www.sychophants.com">
<xs:import namespace="http://www.sychophants.com" schemaLocation="current_obs.xsd"/>
...然后是一些其他定义...
<xs:element name="noInDatPletd" ref="no:in_dat"/>
其中 in_dat 存在于另一个组织编写的模式中。我本质上想做的是创建一个模式,其中包含在其他组织的 XSD 中定义的 in_dat 类型的元素。
我是否已经接近正确了?我对 XML 还很陌生。
我不断
http://location_of_my_xsd/temp.xsd:79:9: Invalid: Undefined element
no{http://www.sychophants.com}:in_dat referenced from content model
从 http://www.w3.org/2001/03/webdata/ 获取信息xsv,这是一个模式验证器。
谢谢。
编辑: 谢谢楼上两位的回复。问题似乎是其他组织没有在其架构中定义 targetNamespace 属性。结果是我无法将命名空间导入到我的架构中,这意味着我无法使用提供的类型。
我必须复制/粘贴代码,这是我想避免的......但我想你不可能拥有你想要的一切。
I have the following start of an XSD:
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:no="http://www.sychophants.com">
<xs:import namespace="http://www.sychophants.com" schemaLocation="current_obs.xsd"/>
...and then some other definitions...
<xs:element name="noInDatPletd" ref="no:in_dat"/>
Where in_dat exists in a schema written by another organization. What I essentially want to do us create a schema that will contain an element of the in_dat type that is defined in the other ogranization's XSD.
Am I even close to having this correct? I'm pretty new to XML.
I keep getting
http://location_of_my_xsd/temp.xsd:79:9: Invalid: Undefined element
no{http://www.sychophants.com}:in_dat referenced from content model
from http://www.w3.org/2001/03/webdata/xsv, which is a schema validator.
Thanks.
edit:
Thanks to the two of you who replied. The problem appears to be that the other organization did not define a targetNamespace attribute in their schema. The result is that I cannot import the namespace into my schema, which means I cannot use the type provided.
I had to copy/paste the code, which is what I wanted to avoid... but you can't have everything you want, I guess.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我只看到一个明显的错误:您使用
ref="no:in_dat"
来引用类型。您应该在那里使用type="no:in_dat"
。ref
将引用全局元素(并且不应与name
属性)。除此之外,您是否将外部模式传递给您自己的模式旁边的验证器?当然需要用您的模式进行验证。
I see only one obvious error: you use
ref="no:in_dat"
for referencing a type. You should usetype="no:in_dat"
there.ref
would reference a global element (and should not be used together with thename
attribute).Apart from that, have you passed the external schema to the validator beside your own schema? It is of course needed to validate with your schema.
除了将 ref= 更改为 type= 之外,您的架构定义看起来是正确的。从错误消息来看,我猜测架构验证器无法从提供的 schemaLocation 加载 current_obs.xsd ,这是有道理的。验证器无法验证是否存在名为 in_dat 的类型,因为它无法导入架构。
Besides changing ref= to type=, your schema definition looks correct. From the error message, I'm guessing that the schema validator is not able to load the current_obs.xsd from the schemaLocation provided, which would make sense. The validator would have no way of verifying whether there is a type called in_dat since it could not import the schema.