Estoy serializando un objeto usando C#. Estoy obteniendo el resultado en este formato dado abajoserialización xml - eliminar el espacio de nombres
<?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>
Pero quiero obtener el resultado en este formato.
<?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>
aquí mi código
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; }
}
tal vez estos le ayudarán http://stackoverflow.com/questions/625927/omitting-all-xsi-and-xsd-namespaces-when -serializing-un-objeto-en-net http://stackoverflow.com/questions/6037948/remove-namespaces-during-xml-serialization – Mithir
duplicado posible de [omisión de todos los espacios de nombres xsi y xsd al serializar un ob ject en .NET?] (http://stackoverflow.com/questions/625927/omitting-all-xsi-and-xsd-namespaces-when-serializing-an-object-in-net) –