声明xml架构命名空间后找不到数据类型
我无法理解声明XML模式的某些行为 问题: 此xml架构工作正常:声明xml架构命名空间后找不到数据类型,xml,schema,Xml,Schema,我无法理解声明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="htt
*<?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>*
*
*
但是,如果我更改targetnamespace以外的任何内容,该模式将不会找到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
和默认名称空间是相同的,因此它可以工作;在第二个例子中,它们是不同的,所以它不是
如何修复它?这取决于你想要实现什么,你还没有告诉我们。嗨,迈克尔,谢谢你回答这个问题。我仍然不理解“当您声明complexType之类的组件时,它会进入模式的targetNamespace”部分。我已经声明了xsd:complexType。我使用了xsd前缀。那么为什么xsd:complexType会转到目标名称空间呢?你误解了我的答案。在模式
中编写时,其效果是声明一个类型,其本地名称为“foo”,其命名空间为包含模式文档的targetNamespace。