定义我的sympleTypes给出“类型未声明,或者不是简单类型”

问题描述 投票:0回答:1

我定义了两个sympleTypes(CommonTypes.xsd),我想在其他几个XSD文件(例如MotorList.xsd)中使用。

我使用Visual Studio进行开发。 Visual Studio不会抱怨任何麻烦。这两个文件的“构建操作”均设置为“嵌入资源”。但是,当我运行验证XSD文件的应用程序时,我得到“未声明类型http://Ford/Mustang/PowerPlugin/CommonTypes:powerType”,或者它不是简单类型。”

怎么了?

感谢您的帮助。

文件CommonTypes.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
           targetNamespace="http://Ford/Mustang/PowerPlugin/CommonTypes">

  <xs:simpleType name="powerType" >
    <xs:restriction base="xs:decimal">
      <xs:minInclusive value="0"/>
    </xs:restriction>
  </xs:simpleType>

  <xs:simpleType name="unitType" final="restriction" >
    <xs:restriction base="xs:string">
      <xs:enumeration value="kW" />
      <xs:enumeration value="PS" />
      <xs:enumeration value="Nm" />
    </xs:restriction>
  </xs:simpleType>
</xs:schema>

文件MotorList.xsd:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema targetNamespace="http://MyNamespace/MyTypes" 
           xmlns:xs="http://www.w3.org/2001/XMLSchema" 
           xmlns:commonTypes="http://Ford/Mustang/PowerPlugin/CommonTypes">

  <xs:import namespace="http://Ford/Mustang/PowerPlugin/CommonTypes"
             schemaLocation="CommonTypes.xsd"/>

  <xs:element name="MotorList">
    <xs:complexType>
      <xs:sequence>
        <xs:element minOccurs="0" maxOccurs="unbounded" name="Prime">
          <xs:complexType>
            <xs:attribute name="cylinder" type="xs:positiveInteger" use="required" />
            <xs:attribute name="power" type="commonTypes:powerType" use="required" />
            <xs:attribute name="unit" type="commonTypes:unitType" use="optional" />
          </xs:complexType>
        </xs:element>
      </xs:sequence>
    </xs:complexType>
  </xs:element>
</xs:schema>
xml xsd xsd-validation
1个回答
0
投票

您的架构文档很好(我用Saxon对其进行了测试)。因此,问题在于您使用它们的方式(您几乎没有告诉我们)。一种可能是模式处理器实际上没有找到CommonTypes.xsd文档-一种检查的好方法是引入故意的错误并查看是否得到报告。然后告诉我们您如何调用失败的验证(以及您使用的是哪种架构处理器)。

© www.soinside.com 2019 - 2024. All rights reserved.