【发布时间】:2014-03-17 21:24:58
【问题描述】:
我已经通过 xsd.exe 工具生成了一个类。
这是架构的相关部分:
<xs:element minOccurs="0" name="propertyLine">
<xs:complexType>
<xs:sequence>
<xs:element minOccurs="0" maxOccurs="unbounded" name="value">
<xs:complexType mixed="true">
<xs:attribute name="name" type="xs:string" />
</xs:complexType>
</xs:element>
</xs:sequence>
</xs:complexType>
</xs:element>
在 xsd 生成类之后,我得到“propertyLine”类型的数组:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "2.0.50727.3038")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType=true)]
public partial class MainSubMessageInfoValue {
private string nameField;
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string name {
get {
return this.nameField;
}
set {
this.nameField = value;
}
}
}
所以我通过以下方式将数据设置为名称属性:
propertyLine[0].name = "data";
但现在我想将数据设置到元素 "value"(具有“name”属性的元素)中。
我想要实现的是:
<value name="data">Bla Bla Bla</value>
我怎样才能通过代码做到这一点?如何将“Bla Bla Bla”设置为“value”?
【问题讨论】: