C#XmlElement是同一元素的两倍
我目前正在开发一个模块来生成XML文件 作为列表实例化的毕业生,我的标签在开始时出现两次(操作_unitaire) [……] 有人有过这个问题吗 更新1 如果我尝试重命名对象的名称,请将operation_unitaire重命名为operation_unitairesC#XmlElement是同一元素的两倍,c#,xml,attributes,C#,Xml,Attributes,我目前正在开发一个模块来生成XML文件 作为列表实例化的毕业生,我的标签在开始时出现两次(操作_unitaire) [……] 有人有过这个问题吗 更新1 如果我尝试重命名对象的名称,请将operation_unitaire重命名为operation_unitaires [DataContract] public class operations_unitaires : ISerializable { [XmlElement(ElementName = "operation_unitai
[DataContract]
public class operations_unitaires : ISerializable
{
[XmlElement(ElementName = "operation_unitairess", Order = 1, IsNullable = true, Type = typeof(List<operation_unitaire>))]
[DataMember(Name = "operation_unitairess", Order = 1, IsRequired = false)]
public List<operation_unitaire> Operation_unitaire { get; set; } //0..n
[DataContract]
公共类操作设备:ISerializable
{
[xmlement(ElementName=“operation_unitaires”,Order=1,IsNullable=true,Type=typeof(List))]
[DataMember(Name=“operation\u unitaires”,Order=1,IsRequired=false)]
公共列表操作_unitaire{get;set;}//0..n
我有这个结果
<compte_type>DROITS_SUSPENDUS</compte_type>
<stock_epuise>0</stock_epuise>
<operations_unitaires>
<operation_unitairess>
<operation_unitaire>
<categorie_operation>SORTIE</categorie_operation>
<date_operation>2016-02-24T00:00:00</date_operation>
<produit>
<code_bivb />
DROITS_SUSPENDUS
0
出动
2016-02-24T00:00:00
[……]
那么如何停止此标记(操作\u unitaires)?标记不会出现两次
<compte_type>DROITS_SUSPENDUS</compte_type>
<stock_epuise>0</stock_epuise>
<operations_unitaires> <!-- your class operations_unitaires -->
<operation_unitaire> <!-- your collection of operation_unitaire -->
<operation_unitaire> <!-- an instance of of operation_unitaire -->
<categorie_operation>SORTIE</categorie_operation>
<...>
DROITS_SUSPENDUS
0
出动
“我们有名为“行动”的名单”
(这不是您列表中的名称)
[xmlement(ElementName=“operation_unitaire”,Order=1,IsNullable=true,Type=typeof(List))]
[DataMember(Name=“operation\u unitaire”,Order=1,IsRequired=false)]
公共列表操作_unitaire{get;set;}//0..n
然后,您的列表名为“operation_unitaire”。这只是一个层次问题 今天我有这个
[XmlElement(ElementName = "operations_unitaires", Order = 3, IsNullable = false, Type = typeof(operations_unitaires))]
[DataMember(Name = "operations_unitaires", Order = 3, IsRequired = false)]
public operations_unitaires operations_unitaires { get; set; }
谁称这种模式为:
[DataContract]
public class operations_unitaires : ISerializable
{
[XmlElement(ElementName = "operation_unitairess", Order = 1, IsNullable = true, Type = typeof(List<operation_unitaire>))]
[DataMember(Name = "operation_unitairess", Order = 1, IsRequired = false)]
public List<operation_unitaire> operation_unitairess { get; set; } //0..n
因此,这是合乎逻辑的,只需直接从第一个模型调用对象列表!列表的名称与对象的名称相同,尽量保持它们的不同,而且您应该了解C#编码风格。我正在尝试一些测试谢谢,我理解您的意思。那么,如何使此标记不出现?可能[XmlIgnore]我不会尝试用标签做任何花样-最好保持XML描述代码尽可能接近。如果你真的必须改变XML,那么你可能想考虑,但这有点更先进。
<compte_type>DROITS_SUSPENDUS</compte_type>
<stock_epuise>0</stock_epuise>
<operations_unitaires> <!-- your class operations_unitaires -->
<operation_unitaire> <!-- your collection of operation_unitaire -->
<operation_unitaire> <!-- an instance of of operation_unitaire -->
<categorie_operation>SORTIE</categorie_operation>
<...>
[XmlElement(ElementName = "operation_unitaire", Order = 1, IsNullable = true, Type = typeof(List<operation_unitaire>))]
[DataMember(Name = "operation_unitaire", Order = 1, IsRequired = false)]
public List<operation_unitaire> operation_unitaire { get; set; } //0..n
[XmlElement(ElementName = "operations_unitaires", Order = 3, IsNullable = false, Type = typeof(operations_unitaires))]
[DataMember(Name = "operations_unitaires", Order = 3, IsRequired = false)]
public operations_unitaires operations_unitaires { get; set; }
[DataContract]
public class operations_unitaires : ISerializable
{
[XmlElement(ElementName = "operation_unitairess", Order = 1, IsNullable = true, Type = typeof(List<operation_unitaire>))]
[DataMember(Name = "operation_unitairess", Order = 1, IsRequired = false)]
public List<operation_unitaire> operation_unitairess { get; set; } //0..n
[DataContract]
public class operation_unitaire : ISerializable
{
[XmlElement(ElementName = "categorie_operation", Order = 1, IsNullable = false, Type = typeof(string))]
[DataMember(Name = "categorie_operation", Order = 1, IsRequired = true)]
public string categorie_operation { get; set; }