过去,我将很多xsd转换为C#,但今天我面临着一条新的错误消息:“由于未找到具有复杂类型的顶级元素,因此无法生成类。” < / strong>
我在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会引发错误“无法生成类,因为没有复杂类型的顶级元素找到。” 。哪有问题上面的工作文件有什么区别?
<?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,但是得到的只是一个空类。
答案 0 :(得分:1)
我想它不需要创建一个包装原始类型的类,如果通过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
}
小型xsd的XML XML对象是免费的。