XML转实体对象

 public CheckoutOutputParms Checkout(CheckoutInputParms input)
{
	string str = File.ReadAllText(Server.MapPath("App_Data/ShippingTypeList.xml"));
	CheckoutOutputParmsList shipTypeList = new CheckoutOutputParmsList();
	using (StringReader sr = new StringReader(str))//读取xml配置文件
	{
		XmlSerializer xs = new XmlSerializer(typeof(CheckoutOutputParmsList));
		shipTypeList = xs.Deserialize(sr) as CheckoutOutputParmsList;
	}
	List<CheckoutOutputParms> AllshipTypeList = new List<CheckoutOutputParms>();
	AllshipTypeList = shipTypeList.checkoutOutputParmsList;
	CheckoutOutputParms result = GetShipTypeFee(AllshipTypeList, input);
	return result;
}
	
public class CheckoutOutputParmsList
{
    [XmlArray("ShippingInfo")]
    [XmlArrayItem("Table")]
    public List<CheckoutOutputParms> checkoutOutputParmsList { get; set; }
}

public class CheckoutOutputParms
{
    [XmlElement("Areas")]
    public string Areas { get; set; }
    [XmlElement("SOAmount")]
    public int SOAmount { get; set; }
    [XmlElement("ShippingFee")]
    public decimal ShippingFee { get; set; }
}

  

你可能感兴趣的:(xml)