我有一个从 xsd 生成的 c# 类。当我想赋予元素价值时
result res = new result();
res.feed = "123132";
// 这工作 res.data 在这里我找不到 id 和 value,例如我该怎么办res.data.id="something"
我有一个 xml:
<result>
<feed></feed>
<status></status>
<data>
<id></id>
<value></value>
<id></id>
<value></value>
</data>
</result>
生成这个 xsd :
<xs:element name="result">
<xs:complexType>
<xs:sequence>
<xs:element type="xs:string" name="feed"/>
<xs:element type="xs:string" name="status"/>
<xs:element name="data">
<xs:complexType>
<xs:choice maxOccurs="unbounded" minOccurs="0">
<xs:element type="xs:string" name="id"/>
<xs:element type="xs:string" name="value"/>
</xs:choice>
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
</xs:schema>
并使用 xsd.exe 我为它生成了类
public partial class result {
private string feedField;
private string statusField;
private resultData dataField;
/// <remarks/>
public string feed {
get {
return this.feedField;
}
set {
this.feedField = value;
}
}
/// <remarks/>
public string status {
get {
return this.statusField;
}
set {
this.statusField = value;
}
}
/// <remarks/>
public resultData data {
get {
return this.dataField;
}
set {
this.dataField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class resultData {
private string[] itemsField;
private ItemsChoiceType[] itemsElementNameField;
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("id", typeof(string))]
[System.Xml.Serialization.XmlElementAttribute("value", typeof(string))]
[System.Xml.Serialization.XmlChoiceIdentifierAttribute("ItemsElementName")]
public string[] Items {
get {
return this.itemsField;
}
set {
this.itemsField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlElementAttribute("ItemsElementName")]
[System.Xml.Serialization.XmlIgnoreAttribute()]
public ItemsChoiceType[] ItemsElementName {
get {
return this.itemsElementNameField;
}
set {
this.itemsElementNameField = value;
}
}
}
/// <remarks/>
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.0.30319.17929")]
[System.SerializableAttribute()]
[System.Xml.Serialization.XmlTypeAttribute(IncludeInSchema=false)]
public enum ItemsChoiceType {
/// <remarks/>
id,
/// <remarks/>
value,
}