0

I have the following code to load an XML doc from a website (hosted by one.com). Issue: i get an error "Unable to connect to the remote server". I checked several posted regarding the same error message, but the suggestions don't work. If I enter the URL in my web browser it views the XML file.

public partial class WebForm1 : System.Web.UI.Page
    {
            private XmlDocument dbKAA;
            private XmlElement root;

    public WebForm1()
    {

    }
        protected void Page_Load(object sender, EventArgs e)
        {
            //LOAD XML
            XmlDocument dbKAA = new XmlDocument();
            dbKAA.Load("http://www.something.com/XMLfile.xml");
            root = dbKAA.DocumentElement
Dr.Mojo
  • 27
  • 12
  • see answer to this question http://stackoverflow.com/questions/7496913/how-to-load-xml-from-url-on-xmldocument. Using webclient may work. – rbm Sep 09 '15 at 08:44

3 Answers3

1

First download the XML data and then load them in the XmlDocument object

    HttpClient client = new HttpClient();
    string url = "http://(urlHere)";
    HttpResponseMessage response = await client.GetAsync(url);
    string xmlData = await response.Content.ReadAsStringAsync();
    XmlDocument dbKAA = new XmlDocument();
    dbKAA.Load(xmlData);
    root = dbKAA.DocumentElement
0

this is because there must be proxy set in your browser and while accessing the xml file using your code you are not using proxy.

WebProxy webpro = new WebProxy(ProxyAddress);
webpro.Credentials = new NetworkCredential(ProxyUID, ProxyPwd);
WebClient wclient = new WebClient(){ Proxy =webpro};
MemoryStream mstream = new MemoryStream(wc.DownloadData("http://www.something.com/XMLfile.xml"));
XmlTextReader xtr = new XmlTextReader(mstream);
XDoc = XDocument.Load(xtr);
amit dayama
  • 3,246
  • 2
  • 17
  • 28
0

Thanks for the answers. I've tried both, but it still didn't work. I had a chat with an operator of one.com and it appears they don't support asp, .NET, C#. So, that's why neither of the above codes are running.

Thanks anyway for the effort.

Dr.Mojo
  • 27
  • 12