且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

无法生成类,因为找不到具有复杂类型的***元素

更新时间:2023-09-11 22:31:58

你的 XSD 只定义了一个类型(正如 Sergio 所建议的那样).因此,它不能用于 XML 验证,除非它是由另一个 XSD 导入的.同样,像 xsd.exe 这样的其他工具将无法使用它.

You XSD only defines a type (as Sergio also suggested). As such, it cannot be used for validation of XML, unless it is imported by another XSD . Likewise, other tools like xsd.exe will not be able to anything sensible with it.

您可以将其与具有接口定义但没有接口实现的 C# 库进行比较.

You can compare this with a C# library having an interface definition, but no implementation of the interface.

您可以通过多种方式解决此问题.考虑到您当前的代码,我会建议以下内容:

You can fix this in a variety of ways. Considering your current code, I would suggest something along those lines:

<?xml version="1.0"?>
<xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
    xmlns="http://www.unece.org/cefact/namespaces/StandardBusinessDocumentHeader"
    elementFormDefault="qualified" attributeFormDefault="unqualified">

    <xs:complexType name="DocumentIdentification">
        <xs:sequence>
            <xs:element name="Standard" type="xs:string" />
            <xs:element name="TypeVersion" type="xs:string" />
            <xs:element name="InstanceIdentifier" type="xs:string" />
            <xs:element name="Type" type="xs:string" />
            <xs:element name="MultipleType" type="xs:boolean" minOccurs="0" />
            <xs:element name="CreationDateAndTime" type="xs:dateTime" />
        </xs:sequence>
    </xs:complexType>

    <xs:element name="DocumentIdentification" type="DocumentIdentification" />
</xs:schema>

尽管您可以考虑重命名类型名称,以防止读者混淆.一种常见的模式是使用 Type 为类型名添加后缀,在您的情况下为 DocumentIdentificationType.

Though you may consider renaming the type name, to prevent confusion to readers. A common pattern is to suffix typenames with Type, in your case, DocumentIdentificationType.

上面的代码可以用 xsd.exe 导入,没有任何问题.

The code above is importable with xsd.exe without any problems.