C# 错误'';doctype';是一个意外的标记。预期的令牌是';DOCTYPE';。第1行,位置3和#x27;

C# 错误'';doctype';是一个意外的标记。预期的令牌是';DOCTYPE';。第1行,位置3和#x27;,c#,asp.net,google-api,C#,Asp.net,Google Api,大家好,我是新来使用谷歌api获取天气更新的。它的问题给出了一个错误。。 我设置了doctype,但问题没有解决。。请帮我提前谢谢 .aspx文件 <%@ Page Language="C#" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http:

大家好,我是新来使用谷歌api获取天气更新的。它的问题给出了一个错误。。 我设置了doctype,但问题没有解决。。请帮我提前谢谢

.aspx文件

<%@ Page Language="C#"  CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication4.WebForm1" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
    <title>Put Your Title Here</title>
    <style type="text/css">
        #Panel1
        {        
            width:350px;         
        }           
        #Panel1 img
        {
            float:left;
            width:100px;
            height:100px;
            margin-top:10px;
        }
        #Panel1 p
        {        
            float:right;
            margin-top:-10px;
            margin-right:0px;        
        }
        #Panel1 legend
        {        
            background-color:Green;
            color:White;
        }
    </style> 
</head>
<body>
    <form id="form1" runat="server">
        <h1 style="text-align:left">Using The Google Weather API</h1><br /> 
        <div style="text-align:left">
            <b>Enter Location (Postal Code or City): </b><asp:TextBox ID="txtLocation" Text="10007" runat="server"></asp:TextBox>
            <asp:Button ID="btnGo" runat="server" Text="GO" onclick="btnGo_Click" /><br /><br />

            <asp:Panel ID="Panel1" runat="server">
                <asp:Image ImageUrl="" runat="server" ID="icon" /> <br />
                <p>
                    Forecast for <b><asp:Label ID="lblLocation" runat="server"></asp:Label></b><br />
                    Current Condition: <b><asp:Label ID="currCondition" runat="server" Text=""></asp:Label></b><br />
                    <b><asp:Label ID="temp_f" runat="server" CssClass = "temp" Text=""></asp:Label></b>
                    <b><asp:Label ID="temp_c" runat="server" Text=""></asp:Label></b><br />
                    <b><asp:Label ID="humidity" runat="server" Text=""></asp:Label></b><br />
                    <b><asp:Label ID="wind_condition" runat="server" Text=""></asp:Label></b><br />
                    Forecast Date: <b><asp:Label ID="lblForecastDate" runat="server" Text=""></asp:Label></b><br />
                </p>
            </asp:Panel><br />
                <div>
                    <b><asp:Label id="wdcError" runat="server" Visible="false" CssClass="weatherError" ></asp:Label></b>
                </div>
        </div>
    </form>
<br/>       
</body>
</html>

这是因为你的
http://www.google.com/ig/api?weather=“+txtLocation.Text
没有返回xml文件。该链接只是将您重定向到google页面

谷歌在之前的某个时候关闭了天气api。

微软的天气API与谷歌的非常相似

检查此示例


或者你也可以使用

如果你最喜欢的天气应用程序在上周左右突然停止工作,那么尝试刷新或重新安装它是没有意义的。谷歌已经一言不发地关闭了它的天气API,并让依赖它来驱动其天气相关应用程序的开发人员陷入困境。我们剩下的是一堆坏掉的应用程序可能会也可能不会得到修复

它不见了我的朋友试试别的

你可以从这里得到

谢谢

  protected void btnGo_Click(object sender, EventArgs e)
        {
            // retrieve weather for the zip code entered by the user
            getWeatherData();
        }

        public void getWeatherData()
        {
            wdcError.Visible = false;

            // check for empty zip code field
            if (txtLocation.Text.Length == 0)
            {
                wdcError.Visible = true;
                wdcError.Text = "Please enter a location!";
                return;
            }
            // load xml result from Google weather
            XDocument xd = XDocument.Load("http://www.google.com/ig/api?weather=" + txtLocation.Text);

            // used to determine if a node is missing
            int cnt = 0;
            cnt = xd.Descendants("forecast_information").Count();

            // determine if forecast information was returned for the location entered by user
            if (cnt == 0)
            {
                wdcError.Visible = true;
                wdcError.Text = "Forecast Information NOT available for the location";
                return;
            }

            // navigate to the Current Conditions node
            var current_conditions = from currentCond in xd.Root.Descendants("current_conditions")
                                     select currentCond;

            // navigate to the Forecast Information node
            var forcastInfo = from forecastinfo in xd.Root.Descendants("forecast_information")
                              select forecastinfo;

            Panel1.GroupingText = "Today's Weather";

            // retrieve city and forecast date information
            foreach (var item in forcastInfo)
            {
                lblLocation.Text = item.Element("city").Attribute("data").Value;
                lblForecastDate.Text = item.Element("forecast_date").Attribute("data").Value;
            }

            // retrieve current weather conditions information
            foreach (var item in current_conditions)
            {
                currCondition.Text = item.Element("condition").Attribute("data").Value;
                temp_f.Text = item.Element("temp_f").Attribute("data").Value + "&deg;" + "F";
                temp_c.Text = "  (" + item.Element("temp_c").Attribute("data").Value + "&deg;" + "C" + ")";
                humidity.Text = item.Element("humidity").Attribute("data").Value;
                icon.ImageUrl = "http://www.google.com" + item.Element("icon").Attribute("data").Value;
                wind_condition.Text = item.Element("wind_condition").Attribute("data").Value;
            }
        }