如何将外部xsd导入另一个xsd?

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何将外部xsd导入另一个xsd?相关的知识,希望对你有一定的参考价值。

我试图从xsd下面生成类,但它在生成相同的类时会抛出几个错误。

我使用下面的命令从xsd:xsd <Schemaname>.xsd /classes下面生成类

它显示错误: - Error while generating classes for schema TransactionHeader. The element 'http://www.example.com/Category/header:TransactionHeader' is missing

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema 
  targetNamespace="http://www.example.com/Category/assignment" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns:patrn="http://www.example.com/Category/header" 
  xmlns:asgn="http://www.example.com/Category/assignment" 
  xmlns:comm="http://www.example.com/Category/commontypes" 
  elementFormDefault="qualified">
    <xs:annotation>
        <xs:documentation>Include Common Types to get the reference type elements </xs:documentation>
    </xs:annotation>

    <xs:import namespace="http://www.example.com/Category/commontypes" schemaLocation="CommonTypes.xsd "/>
    <xs:annotation>
        <xs:documentation>
            Include Transaction Header for the IATPA Assignment Transaction
             </xs:documentation>
    </xs:annotation>

    <xs:import namespace="http://www.example.com/Category/header" schemaLocation="TransactionHeader.xsd "/>
    <xs:element name="Assignment">
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="patrn:TransactionHeader"/>
                <xs:element ref="comm:AssignmentType"/>
                <xs:element ref="asgn:AssignmentClass" minOccurs="0" maxOccurs="1"/>    
                <xs:element ref="asgn:Packet" minOccurs="0" maxOccurs="1"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="AssignmentClass" type="xs:string">
        <xs:annotation>
            <xs:documentation>
                  Set to Blank -Field Required (By Product Management) for future use
            </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="Packet" type="xs:hexBinary">
        <xs:annotation>
            <xs:documentation>
                  Packet holds the whole Data Blob.Not populated for Cancel Assignments
            </xs:documentation>
        </xs:annotation>
    </xs:element>
</xs:schema>

我完全不知道使用xsd类型。我该如何解决这个问题,以便为所有xsd(包括引用的xsd)生成类。

编辑部分 - TransactionHeader

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="http://www.example.com/Category/header" xmlns:trn="http://www.example.com/Category/header" xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified">
    <xs:element name="TransactionHeader">
        <xs:annotation>
            <xs:documentation>
        This is the schema for the XML wrapper of the transaction header and details the valid fields and the order of the 
        fields to be present in the transaction header
        </xs:documentation>
        </xs:annotation>
        <xs:complexType>
            <xs:sequence>
                <xs:element ref="trn:SenderTransactionID"/>
                <xs:element ref="trn:ReceiverTransactionID"/>
                <xs:element ref="trn:TransactionType"/>
                <xs:element ref="trn:ReceiverPartnerID"/>
                <xs:element ref="trn:SenderPartnerID"/>
                <xs:element ref="trn:InsCoName"/>
                <xs:element ref="trn:InsCoCode"/>
                <xs:element ref="trn:InsClaimOfficeID"/>
                <xs:element ref="trn:InsClaimOfficeBranchCode"/>
                <xs:element ref="trn:InsClaimOfficeName"/>
                <xs:element ref="trn:AssignedToName"/>
                <xs:element ref="trn:AssignedToID"/>
                <xs:element ref="trn:AssignedToAlias"/>
                <xs:element ref="trn:ClaimNumber"/>
                <xs:element ref="trn:AppraiserType"/>
                <xs:element ref="trn:ClaimType"/>
                <xs:element ref="trn:ClientUniqueIdentifier" minOccurs="0"/>
                <xs:element ref="trn:TransactionDateTime"/>
                <xs:element ref="trn:ReceiveDateTime" minOccurs="0"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="SenderTransactionID" type="xs:string"/>
    <xs:element name="ReceiverTransactionID" type="xs:string"/>
    <xs:element name="TransactionType">
        <xs:annotation>
            <xs:documentation>
        field for transactions
    </xs:documentation>
        </xs:annotation>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="ReceiverPartnerID">
        <xs:annotation>
            <xs:documentation>
                For other processings
            </xs:documentation>
        </xs:annotation>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="SenderPartnerID">
        <xs:annotation>
            <xs:documentation>
                Other operations
            </xs:documentation>
        </xs:annotation>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="InsCoName" type="xs:string">
        <xs:annotation>
            <xs:documentation>
        Insurance Company Name
    </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="InsCoCode">
        <xs:annotation>
            <xs:documentation>
                Insurance company code
            </xs:documentation>
        </xs:annotation>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="2"/>
                <xs:maxLength value="4"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="InsClaimOfficeID" type="xs:string">
        <xs:annotation>
            <xs:documentation>
            Insurance Company Claim Office ID
        </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="InsClaimOfficeBranchCode" type="xs:string">
        <xs:annotation>
            <xs:documentation>
        Branch code
    </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="InsClaimOfficeName" type="xs:string">
        <xs:annotation>
            <xs:documentation>
        Name
    </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="AssignedToName" type="xs:string"/>
    <xs:element name="AssignedToID" type="xs:string"/>
    <xs:element name="AssignedToAlias" type="xs:string"/>
    <xs:element name="ClaimNumber">
        <xs:annotation>
            <xs:documentation>
        Claim Number
    </xs:documentation>
        </xs:annotation>
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="4"/>
                <xs:maxLength value="25"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="AppraiserType">
        <xs:simpleType>
            <xs:restriction base="xs:string">
                <xs:minLength value="1"/>
            </xs:restriction>
        </xs:simpleType>
    </xs:element>
    <xs:element name="ClaimType" type="xs:string">
        <xs:annotation>
            <xs:documentation>
        fields
    </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="ClientUniqueIdentifier" type="xs:string">
        <xs:annotation>
            <xs:documentation>
                fields
            </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="TransactionDateTime" type="xs:dateTime">
        <xs:annotation>
            <xs:documentation>
        fields
    </xs:documentation>
        </xs:annotation>
    </xs:element>
    <xs:element name="ReceiveDateTime" type="xs:string">
        <xs:annotation>
            <xs:documentation>
        fields
    </xs:documentation>
        </xs:annotation>
    </xs:element>
</xs:schema>
答案

我使用下面的命令为Assignment.xsd生成类

xsd.exe /c Assignment.xsd

但是当使用如下命令直接添加外部引用的xsd名称,然后成功生成类。

xsd.exe /c Assignment.xsd TransactionHeader.xsd.xsd CommonTypes.xsd

以上是关于如何将外部xsd导入另一个xsd?的主要内容,如果未能解决你的问题,请参考以下文章

如何将 XSD 类型导入根架构?

针对包含 xsd:import without location 的 XSD 验证 XML

根据给定的XSD将XML文件转换为另一个

使用C#导入使用XSD验证XML

将 xsd 导入 wsdl

XSD 到 XML 的导入