c# - How to read xml from web response? -


i trying read xml web response , selected nodes (i.e link) it. have far , showing "system.xml.xmlelement", output.

wrequest method, sends post request url using web request , returns string xml response such as:

<status> <code>201</code> <resources_created> <link href="####" rel="############" title="####" />  </resources_created>  <warnings> <warning>display_date 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 appreciated. many thanks.

the immediate problem (the reason you're seeing system.xml.xmlelement) you're calling tostring on xmlelement, doesn't override method. want use innerxml or outerxml properties instead:

xmlnode elem = xmldoc.documentelement.firstchild; return elem.outerxml; 

that's returning whole of xml of first child, code. next you'll want change element you're looking for, , right attributes.

as side note, i'd recommend using linq xml instead - it's nicer xml api. example:

// todo: rename `wrequest` method; that's horrible. var document = xdocument.parse(wrequest()); var href = document.descendants("link").single().attribute("href").value; 

Comments

Popular posts from this blog

php - Submit Form Data without Reloading page -

linux - Rails running on virtual machine in Windows -

php - $params->set Array between square bracket -