0

I'm trying to load some xml into a XDocument. The XML data is provided by the city of Philadelphia, so that's not something I can change. I had a similar query before, which worked just fine. The xml response also seems to hold up in online XML validators, so how can I load it into my XDocument?

Here's the xml request

Here's my code, slightly simplified (first two lines taken and modified from another function).

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);
}
The Jonas Persson
  • 1,726
  • 1
  • 17
  • 36
  • 1
    `var xDoc = XDocument.Load(searchString );` works also fine... – L.B Jul 22 '14 at 17:12
  • 1
    When I tried again, I got 502 (Bad Gateway). Not sure if it matters, but I'm making this call in the controller in an MVC project. I have an almost identical query in a class library that works just fine. – The Jonas Persson Jul 22 '14 at 19:20

0 Answers0