c# - How to set new XML document from XML feed -
is there possibility set new xml document specific fields xml feed?
public string xmlresult; public void page_load(object sender, eventargs args){ string url = string.format("http://search.twitter.com/search.atom?q=test&show-user=true&rpp=10"); httpwebrequest request = webrequest.create(url) httpwebrequest; using (httpwebresponse response = request.getresponse() httpwebresponse) { streamreader reader = new streamreader(response.getresponsestream()); xmlresult = reader.readtoend(); console.writeline("output: " + xmlresult); } xmldocument doc = new xmldocument(); doc.loadxml(xmlresult); response.contenttype = "text/xml"; response.write(doc.outerxml); }
i make new xml document specific fields in example below.
<feed> <entry> <content></content> <author></author> <created_time></created_time> </entry> </feed>
i find linqtoxml easier use...
var xdoc = xdocument.load("http://search.twitter.com/search.atom?q=test&show-user=true&rpp=10"); xnamespace ns = "http://www.w3.org/2005/atom"; xelement feeds = new xelement("feed", xdoc.descendants(ns + "entry") .select(e=>new xelement("entry", new xelement("id", e.element(ns + "id").value), new xelement("author",e.element(ns + "author").element(ns + "name").value), new xelement("created_time",e.element(ns + "published").value) ) ) ); string xmlstr = feeds.tostring();
Comments
Post a Comment