locked
Read XML Response From Page RRS feed

  • Question

  • User-57867956 posted

    I am using C# and sending data to aspx page.  The success or fail response is sent via XML - how can C# read the XML response sent from the page?

    Monday, November 9, 2015 10:18 AM

All replies

  • User-271186128 posted

    Hi Sir,

    how can C# read the XML response sent from the page?

    Could you please explain more details about your problem? If you want to extract the xml node from the xml file. You could refer to the following articles:

           protected void btnRetrive_Click(object sender, EventArgs e)
            {
                XmlDocument xml = new XmlDocument();
                xml.LoadXml(TextBox1.Text);
    
                DataTable dt = new DataTable();
                dt.Columns.AddRange(new DataColumn[4] { new DataColumn("ID"), new DataColumn("Posted-Date"), new DataColumn("Source"), new DataColumn("Summary") });
    
    
                XmlNodeList list = xml.SelectNodes("/Setting");
    
                StringBuilder sb = new StringBuilder();
                foreach (XmlNode xn in list)
                {
                    XmlNodeList list2 = xn.SelectNodes(".//Details");
    
                    foreach (XmlNode cn in list2)
                    {
                        string id = cn["id"].InnerText;
                        string date = cn["posted-date"].InnerText;
                        string source = cn["source"].InnerText;
                        string summary = cn["summary"].InnerText;
     
                        dt.Rows.Add(id,date,source,summary);
                    }
                }
    
                GridView1.DataSource = dt;
                GridView1.DataBind();
            }

    The screenshot:

    Best regards,
    Dillion

    Monday, November 9, 2015 9:46 PM
  • User-57867956 posted

    So sorry for not enugh details.  I am performing a POST to a page, and the success or failure response is (excuse my ignorance) sent back as XML.  I was wondering how I could read or parse that response so I could konw if hte POST was a success or a fail.

    Tuesday, November 10, 2015 8:29 AM
  • User1223857158 posted

    Hi,

    If you can provide some of relevant code or attempts that you may have made so far, it might be easier for us to guide you and help you get what you need without just giving you a completely unexplained answer that in the long run wouldn't help much. 

    Here is an article about getting the title from a remote webpage using web request, you could refer to it:

    https://frejnorling.wordpress.com/2010/07/22/getting-scraping-the-title-of-a-web-page-using-c/

    Best regards

    Wednesday, November 11, 2015 1:49 AM
  • User-57867956 posted

    <div>

    Hi,

    If you can provide some of relevant code or attempts that you may have made so far, it might be easier for us to guide you and help you get what you need without just giving you a completely unexplained answer that in the long run wouldn't help much. 

    Here is an article about getting the title from a remote webpage using web request, you could refer to it:

    https://frejnorling.wordpress.com/2010/07/22/getting-scraping-the-title-of-a-web-page-using-c/

    Best regards

    </div>

    Ah-hah, that page shows me more on what I need to explain.  I have not tried anything yet, as I have been unsure how to do such, but from your example and the link it appears I should use StreamReader to parse the data.  Sending the data POST is no issue, but "getting" a response from a page is where I struggle.  The data returned from the page will be between <success></success> tags.  If everything is actually a success a value of 0 is returned like <success>0</success> if an error occurs then a value of 1 is returned and the errors are listed out so an error example would be <success>1</success><error>This is why you failed</error>

    So if a <success>0</success> is returned I would want to show a message on screen that shows "Success"

    If a <success>1</success> is returned I would want to show in a label on screen the values between the <error></error> tags so that I can look into further the reason for hte fail.

    Wednesday, November 11, 2015 8:18 AM