我有一个表示XML元素的类:
[System.SerializableAttribute()]
[System.ComponentModel.DesignerCategoryAttribute("code")][System.Xml.Serialization.XmlTypeAttribute(AnonymousType = true, Namespace = "http://www.testingmcafeesites.com/testcat_bl.html")]
[System.Xml.Serialization.XmlRootAttribute("scenario", Namespace = "http://www.testingmcafeesites.com/testcat_bl.html", IsNullable = false)]
public partial class scenario
{
private string nameField;
private description descriptionField;
/// <remarks />
[System.Xml.Serialization.XmlAttributeAttribute("name", Namespace = "http://www.testingmcafeesites.com/testcat_bl.html")]
public string Name
{
get { return this.nameField; }
set { this.nameField = value; }
}
/// <remarks />
[System.Xml.Serialization.XmlElementAttribute("description", Namespace = "http://www.testingmcafeesites.com/testcat_bl.html")]
public description description
{
get { return this.descriptionField; }
set { this.descriptionField = value; }
}
/// <remarks />
[System.Xml.Serialization.XmlNamespaceDeclarations]
public System.Xml.Serialization.XmlSerializerNamespaces XmlNamespaces
{
get
{
var namespaces = new System.Xml.Serialization.XmlSerializerNamespaces();
namespaces.Add("epd", "http://www.testingmcafeesites.com/testcat_bl.html");
return namespaces;
}
set { }
}
}
序列化后,它给出以下结果:
<epd:scenario name="Reuse">
,但我需要得到:
<epd:scenario epd:name="Reuse">
有人能帮我解释一下我应该做什么来实现所需的结果吗?
我试图添加
epd:name
前缀直接进入
XmlAttributeAttribute
,但这里序列化失败了
[System.Xml.Serialization.XmlAttributeAttribute("epd:name", Namespace = "http://www.testingmcafeesites.com/testcat_bl.html")]
public string Name
{
get { return this.nameField; }
set { this.nameField = value; }
}