Reputation: 449
What is the simplest approach to creating an XML document from a multiples tables from a database ie: Orders > OrderItems < Products .... may be :
<Order id="1">
<OrderItem id ="1">
<Product>Wheel</Product>
<Qty>1<Qty/>
<Price>10.00</Price>
</OrderItem>
<Order>
I need it in XML to transform to XHTML for loading into Word.
I am also using MVC3, EF5.
Thanks
Upvotes: 0
Views: 53
Reputation: 10416
You didn't give a ton of detail, but you could use the XmlSerializer class. You could string writer if you're only wanting to output to a string instead.
A code sample from MSDN:
XmlSerializer serializer =
new XmlSerializer(typeof(OrderedItem));
// Create an instance of the class to be serialized.
OrderedItem i = new OrderedItem();
// Set the public property values.
i.ItemName = "Widget";
i.Description = "Regular Widget";
i.Quantity = 10;
i.UnitPrice = (decimal) 2.30;
// Writing the document requires a TextWriter.
TextWriter writer = new StreamWriter(filename);
// Serialize the object, and close the TextWriter.
serializer.Serialize(writer, i);
writer.Close();
Upvotes: 1