我试图将一些xml加载到XDocument中。 XML数据由费城市提供,因此我无法改变。之前我有类似的查询,工作得很好。 xml响应似乎也停留在在线XML验证器中,那么如何将其加载到我的XDocument中呢?
这是我的代码,稍微简化了(前两行从另一个函数中获取和修改)。
string searchString = "http://services.phila.gov/PhillyApi/Data/v1.0/permits?$expand=locations&$filter=(issued_datetime%20gt%20Datetime%272012-12-01%27%20and%20issued_datetime%20le%20Datetime%272014-07-18%27)%20and%20(substringof(%27MAJOR%27,permit_type_code)%20or%20substringof(%27MINOR%27,permit_type_code)%20or%20substringof(%27PARIA%27,permit_type_code)%20or%20substringof(%27NEWCON%27,permit_type_code)%20or%20substringof(%27ENTIRE%27,permit_type_code))";
XDocument xResult = MakeRequest(searchString);
public static XDocument MakeRequest(string requestUrl)
{
HttpWebRequest request = WebRequest.Create(requestUrl) as HttpWebRequest;
HttpWebResponse response = request.GetResponse() as HttpWebResponse;
// This line causes the error 'root element missing'
XDocument xDoc = XDocument.Load(response.GetResponseStream());
return (xDoc);
}