Linq读取XML数据
1、XML数据格式:
<?xml version="1.0"?>
<customers>
<customer>
<id>ALFKI</id>
<name>Alfreds Futterkiste</name>
<address>Obere Str. 57</address>
<city>Berlin</city>
<postalcode>12209</postalcode>
<country>Germany</country>
<phone>030-0074321</phone>
<fax>030-0076545</fax>
<orders>
<order>
<id>10643</id>
<orderdate>1997-08-25T00:00:00</orderdate>
<total>814.50</total>
</order>
<order>
<id>10692</id>
<orderdate>1997-10-03T00:00:00</orderdate>
<total>878.00</total>
</order>
<order>
<id>10702</id>
<orderdate>1997-10-13T00:00:00</orderdate>
<total>330.00</total>
</order>
<order>
<id>10835</id>
<orderdate>1998-01-15T00:00:00</orderdate>
<total>845.80</total>
</order>
<order>
<id>10952</id>
<orderdate>1998-03-16T00:00:00</orderdate>
<total>471.20</total>
</order>
<order>
<id>11011</id>
<orderdate>1998-04-09T00:00:00</orderdate>
<total>933.50</total>
</order>
</orders>
</customer>
</customers>
2、Customer类:
public class Customer
{
public string CustomerID { get; set; }
public string CompanyName { get; set; }
public string Address { get; set; }
public string City { get; set; }
public string Region { get; set; }
public string PostalCode { get; set; }
public string Country { get; set; }
public string Phone { get; set; }
public string Fax { get; set; }
public Order[] Orders { get; set; }
}
3、读取数据
List<Customer> lists = (from customer in XDocument.Load("Customers.xml").Root.Elements("customer")
select new Customer
{
CustomerID = (string)customer.Element("id"),
CompanyName = (string)customer.Element("name"),
Address = (string)customer.Element("address"),
City = (string)customer.Element("city"),
Region = (string)customer.Element("region"),
PostalCode = (string)customer.Element("postalcode"),
Country = (string)customer.Element("country"),
Phone = (string)customer.Element("phone"),
Fax = (string)customer.Element("fax"),
Orders = (from order in customer.Elements("orders").Elements("order")
select new Order
{
OrderID = (int)order.Element("id"),
OrderDate = (DateTime)order.Element("orderdate"),
Total = (decimal)order.Element("total")
}).ToArray()
}).ToList();
Linq读取XML数据的更多相关文章
- wcf序列化大对象时报错:读取 XML 数据时,超出最大
错误为: 访问服务异常:格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出 错: request.InnerException 消息是“反序 ...
- InnerException 消息是“反序列化对象 属于类型 *** 时出现错误。读取 XML 数据时,超出最大字符串内容长度配额 (8192)。(注意细节)
WEB站点在调用我们WCF服务的时候,只要传入的参数过长,就报如下错误: 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: formD ...
- Web Service 或 WCF调用时读取 XML 数据时,超出最大字符串内容长度配额(8192)解决方法
1.调用服务时服务 当我们使用 Web Service 或 WCF 服务时,常把读取的数据转化为string类型(xml格式),当数据量达到一 定数量时,会出现以下异常: 错误:格式化程序尝试对消息反 ...
- 读取 XML 数据时,超出最大字符串内容长度配额 (8192)
格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://www.thermo.com/informatics/xmlns/limswebservice 进行反序列化时出错: Process ...
- 格式化程序尝试对消息反序列化时引发异常: 尝试对参数 http://tempuri.org/ 进行反序列化时出错: GetLzdtArticleResult。InnerException 消息是“反序列化对象 属于类型 lzdt.DTO.Dtolzdt[] 时出现错误。读取 XML 数据时,超出最大
当遇到这个错误的时候郁闷了好长时间报错是字符串长度过大可是修改了MaxStringContentLength”属性的值却不起作用最后才发现还是因为配置文件配置的问题在服务端 格式化程序尝试对消息反序列 ...
- XML序列化器读取XML数据
PS:标题我还真的不知道该怎么取比较好,大家将就下吧^_^ 场景:上周接到一个任务,要求我把ASP写的会员充值功能,用ASP.NET复制一遍,没有给我需求文档,就是让我根据代码去分析业务逻辑,然后看到 ...
- 用php读取xml数据
parser是php内置的一个用来处理xml的解析器,它的工作由三个事件组成:起始标签. 读取数据.结束标签. 也就是说在对xml进行处理的时候每当遇到起始标签.数据和结束标签的时候函数会做相应的动作 ...
- [drp 4] 使用dom4j,读取XML数据,保存至数据库
导读:上篇文章介绍了用XML文件配置数据库的连接,然后通过读取XML文件连接数据库的内容,本篇博客介绍读取XML文件,进行数据持久化的操作.PS:从某种意义上来说,经过Scheme校正的XML文件,本 ...
- 使用Java读取XML数据
---------------siwuxie095 工程名:TestReadXML 包名:com.siwuxie095.xml 类名:ReadXML.java 打开资源管理器,在工程 TestRead ...
随机推荐
- iOS-APP-Icon 图标启动图及名字的设置
本文讲下appIcon图标.启动图及名字的设置 icon for iOS 图标大小参照苹果官网:https://developer.apple.com/library/ios/qa/qa1686/_i ...
- 在windows上面安装并用jupyter运行pyspark
1,下载hadoop winutils 设置HADOOP_HOME 2.下载spark,设置SPARK_HOME,将%SPARK_HOME%/加入到PATH路径下 3.安装Anaconda 就是py ...
- 【Educational Codeforces Round 36 C】 Permute Digits
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] //从大到小枚举第i(1..len1)位 //剩余的数字从小到大排序. //看看组成的数字是不是小于等于b //如果是的话. //说 ...
- [AngularFire] Firebase OAuth Login With Custom Firestore User Data
import { NgModule } from '@angular/core'; import { AuthService } from './auth.service'; import { Ang ...
- 8lession-基础类型转化
Python数据类型转换 有时候,我们需要对数据内置的类型进行转换,数据类型的转换,你只需要将数据类型作为函数名即可. 以下几个内置的函数可以执行数据类型之间的转换.这些函数返回一个新的对象,表示转换 ...
- c#的中英文混合字符串截取指定长度,startidx从0开始
//c#的中英文混合字符串截取指定长度,startidx从0开始 by gisoracle@126.com public string getStrLenB(string str, int start ...
- LoadRunner IP欺骗使用
- 免费的EmBitz可替代Keil MDK开发STM32、NXP项目
一.背景 由于使用之前开发STM32是基于Keil MDK编译环境开发的,由于该软件是收费的,想用个免费开源的软件来替代Keil,EmBitz编译器是免费的,可以完全替代开发.下载程序支持J-Link ...
- AutoCAD 出现“安全系统(软件锁许可管理器)不起作用或未正确安装”的解决方法
感谢高飞鸟提供解决方案.当AutoCAD或自动桌子公司的其它产品在启动过程中突然停电或其它原因造成操作系统重启时,可能会造成这些产品的许可出错而无法再运行.一般出错后第一次进入时,会提示你“产品需要激 ...
- 微信支付v2开发(10) 全网发布
关键字:微信公众平台 微信支付 全网发布 作者:方倍工作室 原文:http://www.cnblogs.com/txw1958/p/wxpay-publish.html 在这篇微信公众平台开发教程中, ...