How to read xml from web response? [duplicate]




This question already has an answer here:




I am trying to read xml from web response and get selected nodes (i.e link) from it. This is what I have so far and its showing "System.Xml.XmlElement", as an output.


WRequest method, sends a POST request to url using web request and returns a string xml response such as:



<status> <code>201</code>
<resources_created>
<link href="####" rel="############" title="####" />
</resources_created>
<warnings> <warning>display_date is read-only</warning> </warnings>
</status>


ReadUri2 method



public static string readUri2()
{
string uri = "";
string xml = WRequest();

XmlDocument xmlDoc = new XmlDocument();
xmlDoc.LoadXml(xml);

XmlNode elem = xmlDoc.DocumentElement.FirstChild;
uri = elem.ToString();
return uri;

}


PageLoad calls



protected void Page_Load(object sender, EventArgs e)
{
string uri = readUri2();
Label1.Text = Server.HtmlEncode(uri);

}


Any help would be very much appreciated. Many thanks.


No comments:

Post a Comment