Linq中的XDocument怎样解析这样的XML?
来源:互联网 发布:rar解压软件 mac版 编辑:程序博客网 时间:2024/05/17 22:13
<?xml version="1.0" encoding="utf-8" ?>
<string xmlns="http://www.webserviceX.NET"><?xml version="1.0" encoding="utf-16"?> <CurrentWeather> <Location>Beijing, China (ZBAA) 39-56N 116-17E 55M</Location> <Time>Feb 22, 2011 - 02:30 AM EST / 2011.02.22 0730 UTC</Time> <Wind> from the SSE (160 degrees) at 4 MPH (4 KT) (direction variable):0</Wind> <Visibility> less than 1 mile:0</Visibility> <SkyConditions> clear</SkyConditions> <Temperature> 46 F (8 C)</Temperature> <DewPoint> 23 F (-5 C)</DewPoint> <RelativeHumidity> 39%</RelativeHumidity> <Pressure> 30.03 in. Hg (1017 hPa)</Pressure> <Status>Success</Status> </CurrentWeather></string>
16:30:59
我的错误的解析代码如下:
private void displayCurrentWeatherData(string xmlContent)
{
try
{
if (xmlContent != string.Empty)
{
XDocument xmlUsers = XDocument.Parse(xmlContent);//Linq
{
try
{
if (xmlContent != string.Empty)
{
XDocument xmlUsers = XDocument.Parse(xmlContent);//Linq
var weather = from user in xmlUsers.Descendants("CurrentWeather")
select new CurrentWeather
{
Location = (string)
user.Element("Location").Value,
Time = (string)
user.Element("Time").Value,
Wind = (string)
user.Element("Wind").Value,
Visibility = (string)
user.Element("Visibility").Value,
SkyConditions = (string)
user.Element("SkyConditions").Value,
Temperature = (string)
user.Element("Temperature").Value,
DewPoint = (string)
user.Element("DewPoint").Value,
RelativeHumidity = (string)
user.Element("RelativeHumidity").Value,
Pressure = (string)
user.Element("Pressure").Value,
Status = (string)
user.Element("City").Value
};
select new CurrentWeather
{
Location = (string)
user.Element("Location").Value,
Time = (string)
user.Element("Time").Value,
Wind = (string)
user.Element("Wind").Value,
Visibility = (string)
user.Element("Visibility").Value,
SkyConditions = (string)
user.Element("SkyConditions").Value,
Temperature = (string)
user.Element("Temperature").Value,
DewPoint = (string)
user.Element("DewPoint").Value,
RelativeHumidity = (string)
user.Element("RelativeHumidity").Value,
Pressure = (string)
user.Element("Pressure").Value,
Status = (string)
user.Element("City").Value
};
那位高手可以给我讲讲我错在那里呀?
- Linq中的XDocument怎样解析这样的XML?
- Linq To Xml 备忘录1(XDocument, XElement的使用)
- [代码]创建XDocument对象(LINQ to XML)
- ios上如何解析这样的xml
- LINQ解析XML
- 使用Linq解析xml
- XML(4)XDocument和XmlDocument搜索指定的节点
- C# XDocument的使用
- xml解析之利器--XDocument,XElement,XAttribute等类
- XDocument
- C#中的Linq to Xml
- C# 中的默认命名空间的范围 (LINQ to XML)
- XML的LINQ操作
- XDocument 保存和加载XML文档
- asp.net中,使用XDocument操作XML
- XDocument操作xml文件基本操作
- XmlDocument和XDocument搜索xml比较
- LINQ学习心得分享--------(四)LINQ TO XML实用解析
- 一位软件工程师的6年总结
- 使用的BlackBerry® Tablet OS SDK for Adobe® AIR®开发应用(三)
- libjingle Developer Guide阅读
- 在ASP.NET 2.0中打印(打印控件)
- Android make脚本简记
- Linq中的XDocument怎样解析这样的XML?
- 家庭记账软件(原创)
- 运行程序:xp系统中在运行(cmd)中运行程序
- DirectX图形的设备类型-D3D入门
- DirectX图形的设备类型-D3D入门
- c数组与指针学习笔记
- Linux 脚本编写基础
- poj2823 单调队列
- web developer can feel like kids in a Candy Store