我想通过数据创建 XML,并且我从数据库中接收到数据DataSet
or IList<Booking>
。现在我正在使用DataSet
此代码创建 XML。
string result = String.Empty;
using (StringWriter sw = new StringWriter())
{
ds.WriteXml(sw);
result = sw.ToString();
}
我的 XML 就是这种形式。
<Booking>
<ID>32</ID>
<BookingNumber>12120001</BLNumber>
<ReferenceNo>ABCED11212280007</ReferenceNo>
<Name>Customer Name1</Name>
<Address>Customer Address</Address>
</Booking>
<Booking>
<ID>33</ID>
<BookingNumber>12120002</BLNumber>
<ReferenceNo>ABCED11212280008</ReferenceNo>
<Name>Customer Name2</Name>
<Address>Customer Address2</Address>
</Booking>
<BookingDetail>
<ID>206</ID>
<BookingID>32</BookingID>
<OrderItem>Item1</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>207</ID>
<BookingID>32</BookingID>
<OrderItem>Item2</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>208</ID>
<BookingID>33</BookingID>
<OrderItem>Item1</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>209</ID>
<BookingID>33</BookingID>
<OrderItem>Item2</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>210</ID>
<BookingID>33</BookingID>
<OrderItem>Item3</OrderItem>
</BookingDetail>
但我想要这种形式的 XML。
<CompleteBooking>
<Booking>
<ID>32</ID>
<BookingNumber>12120001</BLNumber>
<ReferenceNo>ABCED11212280007</ReferenceNo>
<Name>Customer Name1</Name>
<Address>Customer Address</Address>
</Booking>
<BookingDetail>
<ID>206</ID>
<BookingID>32</BookingID>
<OrderItem>Item1</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>207</ID>
<BookingID>32</BookingID>
<OrderItem>Item2</OrderItem>
</BookingDetail>
</CompleteBooking>
<CompleteBooking>
<Booking>
<ID>33</ID>
<BookingNumber>12120002</BLNumber>
<ReferenceNo>ABCED11212280008</ReferenceNo>
<Name>Customer Name2</Name>
<Address>Customer Address2</Address>
</Booking>
<BookingDetail>
<ID>208</ID>
<BookingID>33</BookingID>
<OrderItem>Item1</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>209</ID>
<BookingID>33</BookingID>
<OrderItem>Item2</OrderItem>
</BookingDetail>
<BookingDetail>
<ID>210</ID>
<BookingID>33</BookingID>
<OrderItem>Item3</OrderItem>
</BookingDetail>
</CompleteBooking>
谁能帮我创建这种类型的 XML?