2010-11-05 38 views
1

當我使用xsd.exe爲給定的XML生成具有最小元數據的C#類時,它是否識別數值屬性(和InnerTextes)並將它們映射到數值類型的屬性(即:int,double)?xsd.exe是否識別數字字段?

+2

你有什麼嘗試?爲它提供一個簡單的XML文件,其中包含您想要測試的類型並查看結果。會比問這裏要快。 – Oded 2010-11-05 11:29:18

+0

@Oded對我來說也許會更快,但是如果每個遇到同樣疑問的人都必須對它進行測試,我認爲他們會發現速度更快,只需要在Google上找到並找到它。 – 2010-11-05 11:39:09

回答

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; 
    } 
} 

因此,我打算投票「不太可靠,如果有的話」。