2013-02-07 130 views
0

因为我的XSD不适用于Visual Studio 2010,所以我使用它来生成一个。我和生成的不同之处在于层次结构?我使用dtype来调用complexetypes。为什么这不起作用?XML Schema xsd禁止类型

的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> 

回答

1

的第一个问题是你的模式文档不是格式良好的。

一旦提供了复杂类型'top'的缺失结束标记,下一个问题就是您指的是名为chield1chield2的类型,有时称为空名称空间。也就是说,他们的扩展名不会标识特定的名称空间; XSD和许多其他规范将空名称空间视为仅仅是另一个名称空间,它不会有名称。

与此同时,您的模式文档在名称空间top.xsd中声明了两种类型,分别为chield1chield2。 (顺便说一下,这不是一个好的命名空间名称 - 尽管由于复杂的原因,许多工具不会强制执行此规则,但命名空间名称应该是绝对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命名空间声明可以放在元素的声明,而不是任何共同的祖先;一种常见的模式是将其放在架构元素上。