using System;
using System.Xml;
using System.Xml.Serialization;
using System.IO;
/* The XmlRootAttribute allows you to set an alternate name
(PurchaseOrder) of the XML element, the element namespace; by
default, the XmlSerializer uses the class name. The attribute
also allows you to set the XML namespace for the element. Lastly,
the attribute sets the IsNullable property, which specifies whether
the xsi:null attribute appears if the class instance is set to
a null reference. */
[XmlRootAttribute("PurchaseOrder", Namespace = "http://www.cpandl.com",
IsNullable = false)]
public class PurchaseOrder
{
public Address ShipTo;
public string OrderDate;
/* The XmlArrayAttribute changes the XML element name
from the default of "OrderedItems" to "Items". */
[XmlArrayAttribute("Items")]
public OrderedItem[] OrderedItems;
public decimal SubTotal;
public decimal ShipCost;
public decimal TotalCost;
}
public class
C# xmlserializer
C# XML序列化详解
最新推荐文章于 2024-09-03 15:36:26 发布
本文详细探讨了C#中XMLSerializer的使用,包括如何序列化和反序列化对象,以及在处理XML文件时的关键技巧和最佳实践。通过实例代码,深入理解XML序列化在C#应用程序开发中的重要性。

最低0.47元/天 解锁文章
522

被折叠的 条评论
为什么被折叠?



