<?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
};
那位高手可以给我讲讲我错在那里呀?