将 WSDL 对象获取到 SQL 数据库中

发布于 2024-12-10 19:24:17 字数 406 浏览 0 评论 0原文

所以我不想问这个问题,但过去 10 个小时的搜索和尝试编码却一无所获。

我有一个附加了 SQL 数据库的 Visual Studio 项目。我需要将数据从 google 天气服务 API 提取到 sql 表中。

网络服务调用是针对此网站 google api call

以及其他几个网站像accuweather和NOAA一样来显示三者之间的差异。该项目的目标是查看数据是否相对相同,或者是否使用了不同的气象站,如果是,是否会导致向用户报告天气的方式存在显着差异。

我缺少的是该对象的解释器可以允许我将温度、湿度等放入 SQL 表中

有没有人以前做过此操作并有一些提示或参考?

So I hate to ask this but the last 10 hours of searching and attempting to code have turned up nothing.

I have a visual studio project with an SQL database attached. I need to pull data from a google weather service API into the sql table.

The webservice call is to this site google api call

As well as a couple other sites like accuweather and NOAA to show the differences between the three. The projects goal is to see whether the data is relatively the same or if different weather stations are bring used, and if so does it cause a significant difference in the way the weather is reported to the user.

What I'm missing is an interpreter for the object can allow me to put the temp, humidity ect into a sql table

Has anyone done this before and have some tips or references?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

榕城若虚 2024-12-17 19:24:17

以下是如何使用 Linq to XML 解析响应

实例:http://balexandre.com/stackoverflow/7789623/

该链接还包括源代码,但是使用 Linq to XML 进行解析快速、简单、有趣且极其简单:

private GoogleWheatherInfo parseGoogleWeatherResponse(string url)
{
    GoogleWheatherInfo gw = new GoogleWheatherInfo();

    // get the XML
    XDocument doc = XDocument.Load(url);

    // parse data
    gw.ForecastInformation = (from x in doc.Descendants("forecast_information")
                              select new GWForecastInfo
                              {
                                  City = x.Descendants("city").First().Attribute("data").Value,
                                  PostalCode = x.Descendants("postal_code").First().Attribute("data").Value,
                                  Latitude = long.Parse(string.IsNullOrEmpty(x.Descendants("latitude_e6").First().Attribute("data").Value) ? "0" : x.Descendants("latitude_e6").First().Attribute("data").Value),
                                  Longitude = long.Parse(string.IsNullOrEmpty(x.Descendants("longitude_e6").First().Attribute("data").Value) ? "0" : x.Descendants("longitude_e6").First().Attribute("data").Value),
                                  ForecastDate = DateTime.ParseExact(x.Descendants("forecast_date").First().Attribute("data").Value, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                                  CurrentDate = DateTime.ParseExact(x.Descendants("current_date_time").First().Attribute("data").Value, "yyyy-MM-dd HH:mm:ss K", CultureInfo.InvariantCulture),
                                  UnitSystem = x.Descendants("unit_system").First().Attribute("data").Value
                              }).Single();

    gw.CurrentCondition = (from x in doc.Descendants("current_conditions")
                           select new GWCurrentCondition
                           {
                               Condition = x.Descendants("condition").First().Attribute("data").Value,
                               TemperatureC = long.Parse(x.Descendants("temp_c").First().Attribute("data").Value),
                               TemperatureF = long.Parse(x.Descendants("temp_f").First().Attribute("data").Value),
                               Humidity = x.Descendants("humidity").First().Attribute("data").Value,
                               Image = x.Descendants("icon").First().Attribute("data").Value,
                               Wind = x.Descendants("wind_condition").First().Attribute("data").Value
                           }).Single();

    gw.ForecastConditions = (from x in doc.Descendants("forecast_conditions")
                             select new GWForecastCondition
                             {
                                 DayOfWeek = x.Descendants("day_of_week").First().Attribute("data").Value,
                                 Low = double.Parse(x.Descendants("low").First().Attribute("data").Value),
                                 High = double.Parse(x.Descendants("high").First().Attribute("data").Value),
                                 Image = x.Descendants("icon").First().Attribute("data").Value,
                                 Condition = x.Descendants("condition").First().Attribute("data").Value,
                             }).ToList();

    return gw;
}

我希望这能让您了解解析任何 XML 文档是多么容易。

Here is how you can parse the response using Linq to XML

Live Example: http://balexandre.com/stackoverflow/7789623/

The link also include the source code, but the parsing using Linq to XML is quick easy, fun and extremely simple:

private GoogleWheatherInfo parseGoogleWeatherResponse(string url)
{
    GoogleWheatherInfo gw = new GoogleWheatherInfo();

    // get the XML
    XDocument doc = XDocument.Load(url);

    // parse data
    gw.ForecastInformation = (from x in doc.Descendants("forecast_information")
                              select new GWForecastInfo
                              {
                                  City = x.Descendants("city").First().Attribute("data").Value,
                                  PostalCode = x.Descendants("postal_code").First().Attribute("data").Value,
                                  Latitude = long.Parse(string.IsNullOrEmpty(x.Descendants("latitude_e6").First().Attribute("data").Value) ? "0" : x.Descendants("latitude_e6").First().Attribute("data").Value),
                                  Longitude = long.Parse(string.IsNullOrEmpty(x.Descendants("longitude_e6").First().Attribute("data").Value) ? "0" : x.Descendants("longitude_e6").First().Attribute("data").Value),
                                  ForecastDate = DateTime.ParseExact(x.Descendants("forecast_date").First().Attribute("data").Value, "yyyy-MM-dd", CultureInfo.InvariantCulture),
                                  CurrentDate = DateTime.ParseExact(x.Descendants("current_date_time").First().Attribute("data").Value, "yyyy-MM-dd HH:mm:ss K", CultureInfo.InvariantCulture),
                                  UnitSystem = x.Descendants("unit_system").First().Attribute("data").Value
                              }).Single();

    gw.CurrentCondition = (from x in doc.Descendants("current_conditions")
                           select new GWCurrentCondition
                           {
                               Condition = x.Descendants("condition").First().Attribute("data").Value,
                               TemperatureC = long.Parse(x.Descendants("temp_c").First().Attribute("data").Value),
                               TemperatureF = long.Parse(x.Descendants("temp_f").First().Attribute("data").Value),
                               Humidity = x.Descendants("humidity").First().Attribute("data").Value,
                               Image = x.Descendants("icon").First().Attribute("data").Value,
                               Wind = x.Descendants("wind_condition").First().Attribute("data").Value
                           }).Single();

    gw.ForecastConditions = (from x in doc.Descendants("forecast_conditions")
                             select new GWForecastCondition
                             {
                                 DayOfWeek = x.Descendants("day_of_week").First().Attribute("data").Value,
                                 Low = double.Parse(x.Descendants("low").First().Attribute("data").Value),
                                 High = double.Parse(x.Descendants("high").First().Attribute("data").Value),
                                 Image = x.Descendants("icon").First().Attribute("data").Value,
                                 Condition = x.Descendants("condition").First().Attribute("data").Value,
                             }).ToList();

    return gw;
}

I hope this gives you some knowledge on how easy is to parse any XML document.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文