【发布时间】:2019-06-11 06:44:23
【问题描述】:
我试图了解为什么缺少 targetNamespace 会导致我的示例 XML 架构中出现以下错误。如果我删除 targetNamespace (targetNamespace="http://tempuri.org/XMLSchema1.xsd"),我会收到以下错误:
命名空间“http://tempuri.org/XMLSchema1.xsd”不是 可在此参考 架构。 XMLSchema1.xsd 30
“http://tempuri.org/XMLSchema1.xsd:ChildNamePK”身份 未声明约束。 XMLSchema1.xsd 30
如果我重新添加 targetNamespace,这些错误就会消失,但这实际上是一个 sql 注释模式的示例,我为了这篇文章的目的而缩短了它。由于所有元素都是本地的,我想在我的真实模式中删除 targetNamespace。如何在不添加 targetNamespace 的情况下更正架构?
<?xml version="1.0" encoding="utf-8"?>
<xs:schema id="XMLSchema1"
elementFormDefault="qualified"
xmlns="http://tempuri.org/XMLSchema1.xsd"
xmlns:mstns="http://tempuri.org/XMLSchema1.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="Parent">
<xs:complexType>
<xs:sequence>
<xs:element name="Child" maxOccurs="unbounded">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
<xs:element name="OldestChild">
<xs:complexType>
<xs:sequence>
<xs:element name="Name" type="xs:string" />
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
<xs:key name="ChildNamePK">
<xs:selector xpath=".//Child" />
<xs:field xpath="Name" />
</xs:key>
<xs:keyref name="OldestChildFK" refer="ChildNamePK">
<xs:selector xpath=".//OldestChild" />
<xs:field xpath="Name" />
</xs:keyref>
</xs:element>
</xs:schema>
【问题讨论】: