在我的c#代码中,我尝试使用XML序列化而不是xml linq。我不确定哪一个更好。
但是现在我遇到的问题是我的节点来了两次。这就是我的类结构
public class Enterprise
{
public Properties properties;
public List<Person> person;
}
这是我生成的 xml
<?xml version="1.0" encoding="iso-8859-1"?>
<enterprise>
<properties lang="nb">
<Comments>Utlasting av LMS-data</Comments>
<Datasource>SIKT</Datasource>
<Target />
<Datetime>onsdag 24. oktober 2018</Datetime>
</properties>
<person>
<Person>
<sourceid>
<Source>AD</Source>
<Id>123</Id>
</sourceid>
<Userid>mohsin</Userid>
</Person>
如您所见,"人员"标签将出现两次。这就是它的设置方式
Enterprise enterprise = new Enterprise();
enterprise.properties.LanguageCode = "nb";
enterprise.properties.Comments = "Utlasting av LMS-data";
enterprise.properties.Datasource = "SIKT";
enterprise.properties.Target = "";
enterprise.properties.Datetime = DateTime.Now.ToLongDateString();
List<Person> person = new List<Person>();
person.Add(new Person
{
//sourceid = new SourceId
//{
// Id = "123",
// Source = "AD"
//},
Userid = "mohsin"
});
enterprise.person = person;
有谁知道原因?
当你使用List或数组时,它将作为"XmlArrayItem"来克服使用"XmlElement">
public class Enterprise
{
public Properties properties;
[XmlElement("person")]
public List<Person> person;
}