Xsd2code SimpleContent无法正常工作

时间:2013-12-21 14:52:39

标签: xml xsd xsd2code

到目前为止一切顺利,但当我尝试这个xsd错误时出现了。我有一个简单的例子:

<simpleType name="waluta_type">
    <restriction base="token">
        <enumeration value="PLN"/>
        <enumeration value="EUR"/>
        <enumeration value="GBP"/>
        <enumeration value="USD"/>
    </restriction>

<complexType name="cena_type">
    <simpleContent>
        <extension base="double">
            <attribute name="waluta" type="moja:waluta_type" use="required"/>
        </extension>
    </simpleContent> 
</complexType>

xsd2code不会为waluta生成属性:

[System.Xml.Serialization.XmlTypeAttribute(Namespace = "http://example/MS/")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://example/MS/", IsNullable = true)]
public partial class cena_type : EntityBase<cena_type>
{

    [EditorBrowsable(EditorBrowsableState.Never)]
    private double valueField;

    [System.Xml.Serialization.XmlTextAttribute()]
    public double Value { get; set; }


    [System.Xml.Serialization.XmlAttributeAttribute()]
    public waluta_type waluta
    {
        get
        {
            return this.walutaField;
        }
        set
        {
            this.walutaField = value;
        }
    }
}

我收到并且错误[...]不包含'walutaField'的定义,并且没有扩展方法'walutaField'接受类型'ConsoleApplication1.cena_type'的第一个参数可以找到(你是否错过了使用指令或程序集引用?)。有没有人遇到同样的问题,可以给我一个提示?

1 个答案:

答案 0 :(得分:0)

进行一些更改,以便生成将定义添加到现有xsd的类中,然后输入代码:

   [System.CodeDom.Compiler.GeneratedCodeAttribute("System.Xml", "4.0.30319.34230")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(Namespace="http://www.sii.cl/SiiDte")]
[System.Xml.Serialization.XmlRootAttribute(Namespace="http://www.sii.cl/SiiDte", IsNullable=true)]
public partial class cena_type
{

    [EditorBrowsable(EditorBrowsableState.Never)]
    private waluta_type walutaField;

    [EditorBrowsable(EditorBrowsableState.Never)]
    private string valueField;

    [System.Xml.Serialization.XmlAttributeAttribute()]
    public waluta_type waluta
    {
        get
        {
            return this.walutaField;
        }
        set
        {
            this.walutaField = value;
        }
    }

    [System.Xml.Serialization.XmlTextAttribute()]
    public string Value
    {
        get
        {
            return this.valueField;
        }
        set
        {
            this.valueField = value;
        }
    }
}

我使用过这个定义:

 <xs:simpleType name="waluta_type">
    <xs:restriction base="xs:string">
      <xs:enumeration value="PLN"/>
      <xs:enumeration value="EUR"/>
      <xs:enumeration value="GBP"/>
      <xs:enumeration value="USD"/>
    </xs:restriction>
  </xs:simpleType>
  <xs:complexType name="cena_type">
    <xs:simpleContent>
      <xs:extension base="xs:string">
        <xs:attribute name="waluta" type="ns1:waluta_type" use="required" />
      </xs:extension>
    </xs:simpleContent>
  </xs:complexType>

那么,这是版本tha xsd2code?我使用的是新版本。

<NameSpace>FacturasOnline.FacadeDTE</NameSpace><Collection>List</Collection><codeType>CSharp</codeType><EnableDataBinding>False</EnableDataBinding><GenerateCloneMethod>False</GenerateCloneMethod><GenerateDataContracts>False</GenerateDataContracts><DataMemberNameArg>OnlyIfDifferent</DataMemberNameArg><DataMemberOnXmlIgnore>False</DataMemberOnXmlIgnore><CodeBaseTag>Net45</CodeBaseTag><InitializeFields>All</InitializeFields><GenerateUnusedComplexTypes>True</GenerateUnusedComplexTypes><GenerateUnusedSimpleTypes>True</GenerateUnusedSimpleTypes><GenerateXMLAttributes>True</GenerateXMLAttributes><OrderXMLAttrib>False</OrderXMLAttrib><EnableLazyLoading>False</EnableLazyLoading><VirtualProp>False</VirtualProp><PascalCase>False</PascalCase><AutomaticProperties>False</AutomaticProperties><PropNameSpecified>Default</PropNameSpecified><PrivateFieldName>EndWithField</PrivateFieldName><PrivateFieldNamePrefix></PrivateFieldNamePrefix><EnableRestriction>False</EnableRestriction><RestrictionMaxLenght>False</RestrictionMaxLenght><RestrictionRegEx>False</RestrictionRegEx><RestrictionRange>False</RestrictionRange><ValidateProperty>False</ValidateProperty><ClassNamePrefix></ClassNamePrefix><TrackingChangesEnable>False</TrackingChangesEnable><GenTrackingClasses>False</GenTrackingClasses><HidePrivateFieldInIDE>True</HidePrivateFieldInIDE><EnableSummaryComment>False</EnableSummaryComment><EnableExternalSchemasCache>False</EnableExternalSchemasCache><EnableDebug>False</EnableDebug><EnableWarn>False</EnableWarn><ExcludeImportedTypes>False</ExcludeImportedTypes><ExpandNesteadAttributeGroup>False</ExpandNesteadAttributeGroup><CleanupCode>False</CleanupCode><EnableXmlSerialization>False</EnableXmlSerialization><SerializeMethodName>Serialize</SerializeMethodName><DeserializeMethodName>Deserialize</DeserializeMethodName><SaveToFileMethodName>SaveToFile</SaveToFileMethodName><LoadFromFileMethodName>LoadFromFile</LoadFromFileMethodName><EnableEncoding>False</EnableEncoding><EnableXMLIndent>False</EnableXMLIndent><Encoder>UTF8</Encoder><Serializer>XmlSerializer</Serializer><GenerateShouldSerialize>False</GenerateShouldSerialize><BaseClassName>EntityBase</BaseClassName><UseBaseClass>False</UseBaseClass><GenBaseClass>False</GenBaseClass><CustomUsings></CustomUsings>