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. 【leetcode】Restore IP Addresses

    Restore IP Addresses Given a string containing only digits, restore it by returning all possible val ...

  2. Django ~module index

    https://docs.djangoproject.com/en/1.9/py-modindex/ django.conf.urls django.contrib.admin django.db.m ...

  3. Solr安装过程

    Solr安装过程 下载相关资料 solr 4.2.0 http://lucene.apache.org/solr/ 期间安装过 solr 4.3.0 很可惜没有配置成功 apache-tomcat-7 ...

  4. codeforces 582A. GCD Table 解题报告

    题目链接:http://codeforces.com/problemset/problem/582/A 网上很多题解,就不说了,直接贴代码= = 官方题解: http://codeforces.com ...

  5. Linux 命令执行结果输出到屏幕的同时写入到文件中

    tee命令可以做到这一点: 例:ls -al /home | tee log 就可以把命令输出的内容显示在屏幕上的同时也输出至文件log.

  6. iOS 动态计算文本内容的高度

    关于ios 下动态计算文本内容的高度,经过查阅和网上搜素,现在看到的有以下几种方法: 1. //  获取字符串的大小  ios6 - (CGSize)getStringRect_:(NSString* ...

  7. Redis事件管理(一)

    Redis统一的时间管理器,同时管理文件事件和定时器, 这个管理器的定义: #if defined(__APPLE__) #define HAVE_TASKINFO 1 #endif /* Test ...

  8. IE11 的区别

    http://msdn.microsoft.com/zh-tw/visualc/bg182625

  9. 解决VS2010 C++ DLL不能断点调试的问题

    问题产生的过程是这样的,向exe项目(CSharp)中添加dll工程(c++开发)的引用,并将引用工程的属性“Link Library Dependencies”的值设为true,这样,在不加入lib ...

  10. orcad candence 快捷键小结