Class and Xml : Please see my another article. http://www.cnblogs.com/mingmingruyuedlut/p/3436803.html

Following is the mainly function:

        public static List<Order> GetOrderListFromXml(string orderUpsertXmlPath)
{
List<Order> orderList = new List<Order>();
if (File.Exists(orderUpsertXmlPath))
{
XDocument doc = XDocument.Load(orderUpsertXmlPath); orderList = (from order in doc.Root.Elements("Order")
select new Order
{
OrderId = order.Element("OrderID").Value,
OrderNumber = order.Element("OrderNumber").Value,
OrderDate = order.Element("OrderDate").Value,
OrderValue = order.Element("OrderValue").Value,
Reference1 = order.Element("Reference1").Value,
Reference2 = order.Element("Reference2").Value,
DeliveryNotes = order.Element("DeliveryNotes").Value,
Status = order.Element("Status").Value,
OrderEndCustomer = GetEndCustomerInfoFromXml(order),
OrderLineItem = GetLineItemListFromXml(order)
}).ToList();
} return orderList;
} static EndCustomer GetEndCustomerInfoFromXml(XElement order)
{
EndCustomer endCustomerInfo = new EndCustomer();
endCustomerInfo.FirstName = order.Element("EndCustomer").Element("FirstName").Value;
endCustomerInfo.LastName = order.Element("EndCustomer").Element("LastName").Value;
endCustomerInfo.Phone = order.Element("EndCustomer").Element("Phone").Value;
endCustomerInfo.Mobile = order.Element("EndCustomer").Element("Mobile").Value;
endCustomerInfo.Email = order.Element("EndCustomer").Element("Email").Value;
endCustomerInfo.Address1 = order.Element("EndCustomer").Element("Address1").Value;
endCustomerInfo.Address2 = order.Element("EndCustomer").Element("Address2").Value;
endCustomerInfo.Address3 = order.Element("EndCustomer").Element("Address3").Value;
endCustomerInfo.Suburb = order.Element("EndCustomer").Element("Suburb").Value;
endCustomerInfo.Postcode = order.Element("EndCustomer").Element("Postcode").Value;
endCustomerInfo.State = order.Element("EndCustomer").Element("State").Value;
endCustomerInfo.Country = order.Element("EndCustomer").Element("Country").Value;
return endCustomerInfo;
} static List<OrderLineItem> GetLineItemListFromXml(XElement order)
{
List<OrderLineItem> lineItemList = new List<OrderLineItem>(); lineItemList = (from item in order.Elements("LineItems").Elements("LineItem")
select new OrderLineItem
{
OrderID = order.Element("OrderID").Value,
LineItemID = item.Element("LineItemID").Value,
SKU = item.Element("SKU").Value,
Title = item.Element("Title").Value,
Quantity = item.Element("Quantity").Value,
SalesPriceEx = item.Element("SalesPriceEx").Value,
SalesPriceInc = item.Element("SalesPriceInc").Value,
DispatchPoint = item.Element("DispatchPoint").Value,
FreightMethod = item.Element("FreightMethod").Value,
Status = item.Element("Status").Value
}).ToList(); return lineItemList;
}

Another article link about this function is :

http://www.codeproject.com/Tips/366993/Convert-XML-to-Object-using-LINQ

.....

Convert XML to Object using LINQ的更多相关文章

  1. RCE via XStream object deserialization && SECURITY-247 / CVE-2016-0792 XML reconstruction Object Code Inject

    catalogue . Java xStream . DynamicProxyConverter . java.beans.EventHandler . RCE via XStream object ...

  2. 无法将类型“System.Nullable`1”强制转换为类型“System.Object”。LINQ to Entities 仅支持强制转换 EDM 基元或枚举类型。

    在一个项目中使用LINQ和EF时出现了题目所示的异常,搜索了很多资料都找不到解决办法,主要是因为EF方面的知识欠缺. 先将情况记录如下,以供以后参考. 查询主要设计两张表,由外键关联: 在进行下面的查 ...

  3. JAXB 操作XML 与 Object

    Java Architecture for XML Binding) 是一个业界的标准,是一项能够依据XML Schema产生Java类的技术.是一种xml与object映射绑定技术标准. JDK5下 ...

  4. ISO 8601: Delphi way to convert XML date and time to TDateTime and back (via: Stack Overflow)

    Recently I needed a way of concerting back and forth ISO 8601 DateTime values used in XML from Delph ...

  5. Entity Framework Code First 在Object Join Linq查询时出现全表查询的语句。

    最近一个项目,使用微软的Entity Framework的ORM框架的项目,部署到现场后,出现了系统缓慢,多个客户端的内存溢出崩溃的问题. 打开了SQL Server Profiler(SQL Ser ...

  6. how to convert Map to Object in js

    how to convert Map to Object in js Map to Object just using the ES6 ways Object.fromEntries const lo ...

  7. LinqToXml (一) Create Xml file By Dom /Linq

    目前,在xml 应用编程领域比较流行的开发模型是W3C 提供的DOM(文档对象模型),在.net Framework 通过命名空间 System.Xml 对该技术提供了支持.随着Linq to XMl ...

  8. XML基础学习02<linq to xml>

    Linq to XML的理解 1:这是一种比较好的操作Xml的工具. àXDocument 文档 àXElement 元素 àXAttribute 属性 àXText 文本 2:这里还是和我们之前创建 ...

  9. LINQ以及LINQ to Object 和LINQ to Entities

    LINQ的全称是Language Integrated Query,中文译成“语言集成查询”,是一种查询技术. LINQ查询通过提供一种跨各种数据源和数据格式使用数据的一致模型,简化了查询过程.LIN ...

随机推荐

  1. struts2 模型驱动

    public class User3Action extends ActionSupport implements ModelDriven<User> { private User use ...

  2. redis与memcache区别总结

    2015年9月2日 14:04:19 总会被问到两者的区别, 在这里总结下: redis 有内置的多种数据结构, list(可用于实现小型队列), hash, set, zset...; memcac ...

  3. 移动端设页面根目录HTML的字体大小

    @media (max-width: 359px){ html { font-size: 62.5%; }}@media (min-width: 360px) and (max-width: 374p ...

  4. Django~queries

    API queries create, retrieve, update and delete

  5. H5 多个视频 循环播放效果

    跟轮播效果差不多 页面HTML结构 <video id="myvideo" width="100%" height="auto" co ...

  6. 【elasticsearch】python下的使用

    有用链接: 最有用的:http://es.xiaoleilu.com/054_Query_DSL/70_Important_clauses.html 不错的博客:http://www.cnblogs. ...

  7. C/S love自编程序

    using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using Sy ...

  8. CString 操作

    CString Left( int nCount ) const;                   //从左边1开始获取前 nCount 个字符 CString Mid( int nFirst ) ...

  9. August 8th 2016, Week 33rd Monday

    Everything is going on, but don't give up trying. 万事随缘,但不要放弃努力. Every time when I want to give up, y ...

  10. vim 打开高亮和关闭高亮

    :set hls 找开高亮 :set nohls 关闭高亮