【问题标题】:Xsd.exe is unable generate class when Importing ComplexType导入 ComplexType 时 Xsd.exe 无法生成类
【发布时间】:2016-02-01 07:12:09
【问题描述】:

我正在尝试在 XSD 文件上运行 Xsd.exe,但出现以下错误。我使用 IMPORT 是因为主机命名空间不同于外部命名空间。

A2.xsd 依赖于 A21.xsd,而 A21.xsd 又依赖于 A22.xsd(都在同一个文件夹中)

ERROR: "The datatype 'http://service.a1.com/base1/2005/:EmployeeDefinition' is missing"

xsd.exe /classes /out:C:\Temp\ "C:\Temp\A2.xsd" /language:CS

A2.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base/2005/" xmlns:c1="http://service.a1.com/base1/2005/" elementFormDefault="qualified">
  <xs:import namespace="http://service.a1.com/base1/2005/" schemaLocation="a21.xsd"/> 
  <xs:element name="Employee" nillable="true" type="c1:EmployeeDefinition" />
</xs:schema>

A21,xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base1/2005/" xmlns:n2="http://service.a1.com/base2/2005/" elementFormDefault="qualified">
 <xs:import namespace="http://service.a1.com/base2/2005/" schemaLocation="a22.xsd"/> 
 <xs:complexType  name="EmployeeDefinition">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="EmployeeID" type="xs:int" />
      <xs:element minOccurs="0" maxOccurs="1" name="FirstName" type="xs:string" />
      <xs:element name="Address" nillable="true" type="n2:AddressDefinition" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

A22.xsd

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://service.a1.com/base2/2005/" elementFormDefault="qualified">
  <xs:complexType name="AddressDefinition">
    <xs:sequence>
      <xs:element minOccurs="1" maxOccurs="1" name="HouseNumber" type="xs:int" />
      <xs:element minOccurs="0" maxOccurs="1" name="StreetName" type="xs:string" />
    </xs:sequence>
  </xs:complexType>
</xs:schema>

请告诉我这里发生了什么。

【问题讨论】:

    标签: xml xsd schema xsd-validation xsd.exe


    【解决方案1】:

    你必须告诉 xsd.exe 引用的所有架构

    xsd.exe /c "C:\Temp\A2.xsd" "C:\Temp\A21.xsd" "C:\Temp\A22.xsd"
    

    【讨论】:

    • 哇,这么简单。一直让我发疯。谢谢
    【解决方案2】:

    如果你有很多xsd,你应该使用配置文件。 例如 GenerateClassFromXSD.xml :

    <xsd xmlns='http://microsoft.com/dotnet/tools/xsd/'>
    <generateClasses language='CS' namespace='Namespace.subnamespace'>
        <schema>A2.xsd</schema>
        <schema>A21.xsd</schema>
        <schema>.\A22.xsd</schema>
    </generateClasses>
    </xsd>
    

    xsd /p:GenerateClassFromXSD.xml

    在此处查看最终提示: Tool that can combine many XSD files into one?

    【讨论】:

      猜你喜欢
      • 2011-05-18
      • 2011-01-02
      • 2022-01-20
      • 2013-11-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多