C#을 사용하여 개체를 serialize하는 중입니다. 나는이 형식으로 결과를 얻고있다.xml serialization - 네임 스페이스 제거
<?xml version="1.0"?>
<Users xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<Users>
<User Id="11005477969327" CreateDate="06/03/2011" LastSendDate="1/1/0001" />
<User Id="11034688201594" CreateDate="04/22/2012" LastSendDate="1/1/0001" />
<Users
</User>
그러나 나는이 형식으로 결과를 원한다. 여기
<?xml version="1.0"?>
<Users>
<User Id="11005477969327" SendDate="1/1/0001" NextSendDate="2/7/2012 11:13:30 AM" />
<User Id="11034688201594" SendDate="1/1/0001" NextSendDate="2/7/2012 11:13:30 AM" />
</Users>
당신은 단순히 당신이 "사용자"특정 노드에서 모든 사용자 항목을 저장하는 것인지, 시리얼에게 [XmlElement("User")]
이 속성으로 [XmlArray("Users")]
를 교체해야
public class Users
{
[XmlArray("Users")]
public List<User> ListData { get; set; }
public string GetXML()
{
System.IO.MemoryStream ms = new System.IO.MemoryStream();
XmlSerializer sr = new XmlSerializer(typeof(Users));
sr.Serialize(ms, this);
ms.Position = 0;
return System.Text.Encoding.UTF8.GetString(ms.ToArray());
}
}
public class User
{
[XmlAttribute("Id")]
public Int64 UserId { get; set; }
[XmlAttribute("CreateDate")]
public string CreateDate { get; set; }
[XmlAttribute("LastSendDate")]
public string LastSendDate { get; set; }
}
어쩌면이 도움이 될 http://stackoverflow.com/questions/625927/omitting-all-xsi-and-xsd-namespaces-when -serializing-AN-객체에 그물을 http://stackoverflow.com/questions/6037948/remove-namespaces-during-xml-serialization 산부인과를 직렬화 때 모든 XSI 및 XSD 네임 스페이스를 생략의 – Mithir
가능한 중복 NET에서 ject?] (http://stackoverflow.com/questions/625927/omitting-all-xsi-and-xsd-namespaces-when-serializing-an-object-in-net) –