由于我的XSD不适用于Visual Studio 2010,我用它来生成一个。我和Generated之间的区别是层次结构?我使用dtype来调用complexetypes。为什么不起作用?
Visual Studio版本:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="top.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="top">
<xs:complexType>
<xs:sequence>
<xs:element name="child1">
<xs:complexType>
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
</xs:element>
<xs:element name="child2">
<xs:complexType>
<xs:attribute name="attribute2" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
我个人认为我的版本很整洁,但是在这一点上出现了一个错误,该类型不能用作参考:
<?xml version="1.0" encoding="utf-8"?>
<xs:schema attributeFormDefault="unqualified"
elementFormDefault="qualified"
targetNamespace="top.xsd"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:element name="top">
<xs:complexType>
<xs:sequence>
<xs:element name="chield1" type="chield1" />
<xs:element name="chield2" type="chield2" />
</xs:sequence>
</xs:element>
<xs:complexType name="chield1">
<xs:attribute name="attribute1" type="xs:string" />
</xs:complexType>
<xs:complexType name="chield2">
<xs:attribute name="attribute2" type="xs:string" />
</xs:complexType>
</xs:schema>
答案 0 :(得分:1)
第一个问题是您的架构文档格式不正确。
一旦提供了复杂类型“top”的缺失结束标记,下一个问题就是您在有时称为null名称空间的名称中引用名为chield1
和chield2
的类型。也就是说,它们的扩展名称不能识别特定的名称空间; XSD和许多其他规范将null命名空间视为仅仅是另一个没有名称的命名空间。
同时,您的模式文档在名称空间chield1
中声明了两个名为chield2
和top.xsd
的类型。 (顺便说一下,这不是一个好的命名空间名称 - 名称空间名称应该是绝对URI,即使由于复杂的原因,许多工具也不会强制执行此规则。)对于元素chield1和chield2的声明不指向这些类型。如果您希望他们这样做,声明应该说:
<xs:element name="chield1"
type="tns:chield1"
xmlns:tns="top.xsd" />
<xs:element name="chield2"
type="tns:chield2"
xmlns:tns="top.xsd" />
实际上,当然,tns的名称空间声明可以在元素声明的任何共同祖先上进行;一个常见的模式是将它放在架构元素上。