【发布时间】:2019-07-26 09:57:13
【问题描述】:
我有一个已转换为 .xsd 文件的 .dtd 文件。这个文件有一个元素Identity:
<xs:element name="Identity">
<xs:complexType mixed="true">
<xs:sequence>
<xs:any minOccurs="0" maxOccurs="unbounded" namespace="##any" />
</xs:sequence>
<xs:attribute name="lastChangedTimestamp" type="xs:string" />
</xs:complexType>
</xs:element>
这会生成以下示例 xml,其中包含一些文本内容:
<Identity lastChangedTimestamp="lastChangedTimestamp1" xmlns="http://tempuri.org/cXML">text</Identity>
我使用 xsd.exe 将 .xsd 转换为 .cs 文件:
[System.CodeDom.Compiler.GeneratedCodeAttribute("xsd", "4.6.1055.0")]
[System.SerializableAttribute()]
[System.Diagnostics.DebuggerStepThroughAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")]
[System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://tempuri.org/cXML")]
[System.Xml.Serialization.XmlRootAttribute(Namespace = "http://tempuri.org/cXML", IsNullable = false)]
public partial class Identity
{
public string Text { get; set; }
private System.Xml.XmlNode[] anyField;
private string lastChangedTimestampField;
/// <remarks/>
[System.Xml.Serialization.XmlTextAttribute()]
[System.Xml.Serialization.XmlAnyElementAttribute()]
public System.Xml.XmlNode[] Any
{
get
{
return this.anyField;
}
set
{
this.anyField = value;
}
}
/// <remarks/>
[System.Xml.Serialization.XmlAttributeAttribute()]
public string lastChangedTimestamp
{
get
{
return this.lastChangedTimestampField;
}
set
{
this.lastChangedTimestampField = value;
}
}
}
但是这不允许我设置身份节点的文本内容:
var credential = new Credential()
{
Identity = new Identity()
{
lastChangedTimestamp = "lastChangedTimestamp1",
//Text = "MyRef" <- would like to set it at this point
}
};
我可以做些什么来确保当我序列化 Identity 对象时,我可以将我的 ref 放入节点的文本内容中,还是不支持?
<Identity lastChangedTimestamp="lastChangedTimestamp1">
MyRef
</Identity>
【问题讨论】:
-
我可以假设您手动添加了
public string Text { get; set; }吗? -
“文本”是我认为可以设置的属性,但在自动生成的代码中不存在。我想避免更改系统生成的代码