xsd.exe是否识别数字字段?

时间:2010-11-05 11:25:56

标签: c# .net xml xsd.exe

当我使用xsd.exe为具有最少元数据的给定XML生成C#类时,它是否识别数字属性(和InnerTextes)并将它们映射到数值类型的属性(即:int,double)?

1 个答案:

答案 0 :(得分:0)

快速测试:

<test>
    <i>123</i>
    <f>12.3</f>
    <s>abc</s>
</test>

然后:

xsd test.xml
xsd test.xsd /c

给出:

  <xs:element name="test">
    <xs:complexType>
      <xs:sequence>
        <xs:element name="i" type="xs:string" minOccurs="0" />
        <xs:element name="f" type="xs:string" minOccurs="0" />
        <xs:element name="s" type="xs:string" minOccurs="0" />
      </xs:sequence>
    </xs:complexType>
  </xs:element>

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string i {
    get {
        return this.iField;
    }
    set {
        this.iField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string f {
    get {
        return this.fField;
    }
    set {
        this.fField = value;
    }
}

/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute(Form=System.Xml.Schema.XmlSchemaForm.Unqualified)]
public string s {
    get {
        return this.sField;
    }
    set {
        this.sField = value;
    }
}

所以我要投票“不太可靠,如果有的话”。