XSD 无法生成 类 但可以处理类似文件

XSD Cannot generate classes but works on similar file

我过去将很多 xsd 转换为 C#,但今天我遇到了一条新的错误消息,对我来说:"cannot generate classes because no top-level elements with complex type were found."

我有 2 个文件有这个问题。我读了很多关于这个的帖子,他们帮助我解决了我遇到的两个问题中的至少一个。

我修复的文件是:

<?xml version="1.0" encoding="utf-8"?>
<xs:schema xmlns:mg="urn:crif-messagegateway:2006-08-23" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:crif-messagegateway:2006-08-23" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="MGRequest" type="xs:string"/>
    <xs:element name="MGResponse" type="xs:string"/>
</xs:schema>

我将其编辑为:

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:mg="urn:crif-messagegateway:2006-08-23" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:crif-messagegateway:2006-08-23" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="MGRequest">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string" />
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
    <xs:element name="MGResponse">
        <xs:complexType>
            <xs:simpleContent>
                <xs:extension base="xs:string" />
            </xs:simpleContent>
        </xs:complexType>
    </xs:element>
</xs:schema>

现在,我也在尝试转换以下 xsd 文件(与之前修复的非常相似),但它 xsd.exe 抛出错误 "cannot generate classes because no top-level elements with complex type were found."。哪个是问题?上面的工作文件有什么区别?

<?xml version="1.0" encoding="UTF-8"?>
<xs:schema xmlns:mg="urn:crif-messagegateway:2006-08-23" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="urn:crif-messagegateway:2006-08-23" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:element name="MGRequest">
        <xs:complexType>
            <xs:sequence>
                <xs:any namespace="##other"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element name="MGResponse">
        <xs:complexType>
            <xs:sequence>
                <xs:any namespace="##other"/>
            </xs:sequence>
        </xs:complexType>
    </xs:element>
</xs:schema>

我也尝试使用 xsd2code,但我得到的只是一个空的 class。

我猜它没有必要创建一个 class 来包装原始类型,如果你 运行 它通过 Liquid XML Objects 你得到这个

namespace LiquidTechnologies.GeneratedLx.Mg
{
    #region Elements
    /// <summary>A class representing the root XSD element MGRequest@urn:crif-messagegateway:2006-08-23</summary>
    /// <XsdPath>schema:schema.xsd/element:MGRequest</XsdPath>
    /// <XsdFile>file://sandbox/schema.xsd</XsdFile>
    /// <XsdLocation>3:5-3:52</XsdLocation>
    [LxSimpleElementDefinition("MGRequest", "urn:crif-messagegateway:2006-08-23", ElementScopeType.GlobalElement)]
    public partial class MGRequestElm
    {
        /// <summary>Holds the <see cref="System.String" /> (xs:http://www.w3.org/2001/XMLSchema:string) value of the element</summary>
        /// <XsdPath>schema:schema.xsd/element:MGRequest</XsdPath>
        /// <XsdFile>file://sandbox/schema.xsd</XsdFile>
        /// <XsdLocation>3:5-3:52</XsdLocation>
        [LxValue(LxValueType.Value, XsdType.XsdString)]
        public System.String Value { get; set; } = "";

    }

    /// <summary>A class representing the root XSD element MGResponse@urn:crif-messagegateway:2006-08-23</summary>
    /// <XsdPath>schema:schema.xsd/element:MGResponse</XsdPath>
    /// <XsdFile>file://sandbox/schema.xsd</XsdFile>
    /// <XsdLocation>4:5-4:53</XsdLocation>
    [LxSimpleElementDefinition("MGResponse", "urn:crif-messagegateway:2006-08-23", ElementScopeType.GlobalElement)]
    public partial class MGResponseElm
    {
        /// <summary>Holds the <see cref="System.String" /> (xs:http://www.w3.org/2001/XMLSchema:string) value of the element</summary>
        /// <XsdPath>schema:schema.xsd/element:MGResponse</XsdPath>
        /// <XsdFile>file://sandbox/schema.xsd</XsdFile>
        /// <XsdLocation>4:5-4:53</XsdLocation>
        [LxValue(LxValueType.Value, XsdType.XsdString)]
        public System.String Value { get; set; } = "";

    }

    #endregion

}

液体 XML 小 xsd 的物品免费。