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. ACL

    http://man.chinaunix.net/linux/debian/debian_learning/ch01s04.html http://blog.csdn.net/xiangliangyu ...

  2. ios 关于使用异步网络请求时block回调的内存注意

    在一个controller中,使用 NSURLSessionDataTask *dataTask = [[NSURLSession sharedSession] dataTaskWithRequest ...

  3. [转] Git 基础 - 打标签

    2.6 Git 基础 - 打标签 打标签 同大多数 VCS 一样,Git 也可以对某一时间点上的版本打上标签.人们在发布某个软件版本(比如 v1.0 等等)的时候,经常这么做.本节我们一起来学习如何列 ...

  4. codeforces Educational Codeforces Round 5 A. Comparing Two Long Integers

    题目链接:http://codeforces.com/problemset/problem/616/A 题目意思:顾名思义,就是比较两个长度不超过 1e6 的字符串的大小 模拟即可.提供两个版本,数组 ...

  5. BestCoder8 1001.Summary(hdu 4989) 解题报告

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4989 题目意思:给出 n 个数,然后将这些数两两相加,得到 n*(n-1) /2 对和,把重复的和去掉 ...

  6. MyEclipse8.5可用注册码(到2018年)

    转载自:http://blog.csdn.net/z123252520/article/details/45873159 Subscriber:zy Subscriber Code:mLR8ZC-85 ...

  7. iOS应用支持IPV6,就那点事儿

    原文连接   果然是苹果打个哈欠,iOS行业内就得起一次风暴呀.自从5月初Apple明文规定所有开发者在6月1号以后提交新版本需要支持IPV6-Only的网络,大家便开始热火朝天的研究如何支持IPV6 ...

  8. nginx 配一个简单的静态文件服务器 和一个虚似机

    下面是个图片服务器: server { listen ; server_name img.xxx.xxx.com; root /data/site/img.xxx.xxx.com; access_lo ...

  9. wifi 4次握手

    转自:http://zhaoxiaobu.blog.51cto.com/878176/407130/ 不管是用WEP加密,还是用WPA,一般如果我们要和AP建立一个连接,要经过两个阶段认证(Authe ...

  10. RESTful架构入门

    理解RESTful架构 - 阮一峰的网络日志http://www.ruanyifeng.com/blog/2011/09/restful RESTful API 设计指南 - 阮一峰的网络日志http ...