我提供了许多XSD以及样本xml。 一个样本xml的片段是:
<tfsChequeId xmlns="http://www.something.com/XMLSchemas/itrs/tfs/v1">
<dic numericCode="20010411199194813505"/>
</tfsChequeId>
此代码段的xsd如下:
<xsd:element name="tfsChequeId" type="tfs:TfsChequeId" minOccurs="1" maxOccurs="1" />
<xsd:complexType name="TfsChequeId">
<xsd:sequence>
<xsd:element name="dic" type="tfs:TfsChequeIdDic" minOccurs="0" maxOccurs="1">
<xsd:annotation>
<xsd:documentation>The Document Identity Code (Doc-ID Code / DIC) is the representation of the document identity as printed on the document (usually also as barcode).
In many cases it also contains additional information for the form (refund rule, check digit, etc.). Several variants of the document identity code exist, but
they all contain at least the information that is included in the document identity number (country, store and serial number).
</xsd:documentation>
</xsd:annotation>
</xsd:element>
</xsd:sequence>
</xsd:complexType>
<xsd:complexType name="TfsChequeIdDic">
<xsd:attribute name="numericCode" type="common:DocumentIdentifierCode">
<xsd:annotation>
<xsd:documentation>The document identity code is the representation of the document identity as printed on the document (usually also as barcode).
</xsd:documentation>
</xsd:annotation>
</xsd:attribute>
</xsd:complexType>
xsd非常复杂。在使用svcutil.exe生成datacontracts时,会生成许多错误。 以下所有形式:
Error: There was a validation error in the schemas provided for code generation:
Source:
Line: 85 Column: 6
Validation Error: Type 'http://www.something.com/XMLSchemas/itrs/common/v1:Docu
mentIdentifierCode' is not declared, or is not a simple type.
生成的datacontract如下:
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.CodeDom.Compiler.GeneratedCodeAttribute("System.Runtime.Serialization", "4.0.0.0")]
[System.Runtime.Serialization.DataContractAttribute(Name="TfsChequeId", Namespace="http://www.something.com/XMLSchemas/itrs/tfs/v1")]
public partial class TfsChequeId : object, System.Runtime.Serialization.IExtensibleDataObject
{
private System.Runtime.Serialization.ExtensionDataObject extensionDataField;
private www.something.com.XMLSchemas.itrs.tfs.v1.TfsChequeIdDic dicField;
public System.Runtime.Serialization.ExtensionDataObject ExtensionData
{
get
{
return this.extensionDataField;
}
set
{
this.extensionDataField = value;
}
}
[System.Runtime.Serialization.DataMemberAttribute(EmitDefaultValue=false)]
public www.something.com.XMLSchemas.itrs.tfs.v1.TfsChequeIdDic dic
{
get
{
return this.dicField;
}
set
{
this.dicField = value;
}
}
}
但是我不知道如何使用它..即设置numericCode? 我们将非常感激地提出任何想法/提示/技巧。
菲奥娜
答案 0 :(得分:1)
您需要做的第一件事是确保您可以在没有错误的情况下运行您的svcutil。我怀疑您的DocumentIdentifierCode是在未包含在命令行中的XSD中定义的。如果真的很复杂,请查看this post如何重构XSD。如果您没有那么多文件,那么使用类似于this post中显示的命令行:将/ mc替换为/ dconly(仅限数据合约),但请确保列出所有XSD。我见过svcutil仍然不能工作的情况,在这种情况下尝试xsd.exe命令行(参见我引用的第一个链接)。
答案 1 :(得分:1)
属性不能与数据合同一起使用。因此,如果您必须严格遵守所提供的架构,则无法使用数据合同。
根据XSD的复杂性,您可以使用svcutil生成适合XML序列化的类。