我无法理解声明XML模式的某些行为。
问题此 xml 架构工作正常:
*<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org" xmlns:ab="http://test.com"
targetNamespace="http://www.example.org"
elementFormDefault="qualified">
<xsd:element name="simple1" type="complexType1"/>
<xsd:complexType name="complexType1">
<xsd:sequence>
<xsd:element name="element1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>*
但是如果我更改目标命名空间除 http://www.example.org 之外的任何内容,则模式找不到complexType1。为什么会这样。这行不通。
*<?xml version="1.0" encoding="windows-1252" ?>
<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns="http://www.example.org" xmlns:ab="http://test.com"
targetNamespace="http://www.example.org99999"
elementFormDefault="qualified">
<xsd:element name="simple1" type="complexType1"/>
<xsd:complexType name="complexType1">
<xsd:sequence>
<xsd:element name="element1" type="xsd:string"/>
</xsd:sequence>
</xsd:complexType>
</xsd:schema>*
提前致谢
当您声明组件(如 complexType
)时,它会进入架构的targetNamespace
。当您引用具有无前缀名称的组件时(如在 type="complexType1"
属性中),这被视为对默认命名空间(在 xmlns 属性中声明)的引用。在您的第一个示例中,targetNamespace
和默认命名空间是相同的,因此它可以工作;在第二个示例中,它们是不同的,所以它不是。
如何解决?这取决于您要实现的目标,而您尚未告诉我们。