Hi,@Julio Bello. You could try to see if the following code is what you want.
public class Program
{
public static void Main()
{
Shipment test = new Shipment();
test.Account = "ACCOUNT";
MyWrapper wrapper = new MyWrapper
{
Items = { test }
};
SerializeToXML(wrapper);
}
static public void SerializeToXML(MyWrapper list)
{
XmlSerializer serializer = new XmlSerializer(typeof(MyWrapper));
using (TextWriter textWriter = new StreamWriter(@"C:\Users\Administrator\Desktop\test.xml"))
{
serializer.Serialize(textWriter, list);
textWriter.Close();
}
}
private static string ObjectToXmlString<TRequest>(TRequest request, string xmlns)
{
var memoryStream = new MemoryStream();
var xmlSerializer = new XmlSerializer(typeof(TRequest));
var streamWriter = new StreamWriter(memoryStream);
// Create XmlSerializerNamespaces to specify the namespaces
var namespaces = new XmlSerializerNamespaces();
namespaces.Add("", xmlns); // Default namespace
namespaces.Add("", "http://api.company.com/schemas/api/company-api-vN.xsd");
xmlSerializer.Serialize(streamWriter, request, namespaces);
memoryStream.Position = 0;
var xmlString = new StreamReader(memoryStream).ReadToEnd();
return xmlString;
}
}
[XmlRoot("Shipment", Namespace = "http://api.company.com/schemas/api/company-api-vN.xsd")]
public class MyWrapper
{
private List<Shipment> items = new List<Shipment>();
[XmlElement("Account")]
public List<Shipment> Items { get { return items; } }
}
[XmlRoot(ElementName = "Shipment") ]
public partial class Shipment
{
[XmlElement(ElementName = "Account")]
public string Account { get; set; }
}
The result:
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.