c# - How to Use GridView to display XML Web Response By Attribute Name Instead of DataSet Column Name -
i'm trying display xml web response using asp.net form gridview. i'm new .net framework i'm struggling of particulars.
i'm developing search engine xml response result of search particular phrase or word. sample of xml response
<response> <lst name="responseheader"> <int name="status">0</int> <int name="qtime">8</int> <lst name="params"> <str name="qf">recordkey</str> <str name="df">text</str> <str name="echoparams">all</str> <str name="indent">true</str> <str name="wt">xml</str> <str name="q">*:*</str> </lst> </lst> <result name="response" numfound="281" start="0"> <doc> <str name="date created">2014-10-30</str> <str name="facility">*****</str> <str name="author">*********</str> <str name="source system id">*******</str> <str name="data source">************</str> <str name="title">engineering initiation</str> <long name="_version_">1504985395557826560</long> </doc> <doc> <str name="date created">2011-09-30</str> <str name="facility">*********</str> <str name="author">************</str> <str name="source system id">***</str> <str name="data source">***************</str> <str name="title">use of registered....</str> <long name="_version_">1504985395859816448</long> </doc> <doc>..... ...........
i blocked out of content idea.
once response use streamreader read xml , put xmldocument.
xmldocument myxmldocument = new xmldocument(); gridview1.datasource = myxmldocument; streamreader myxmlreader = new streamreader(response.getresponsestream()); ds.readxml(myxmlreader); gridview1.datasource = ds.tables["str"]; gridview1.databind();
after load dataset , bind table "str" gridview produces result
name str_text lst_id doc_id qf recordkey 1 df text 1 echoparams 1 indent true 1 wt xml 1 q *fire* 1 date created 2014-10-30 0 facility ***** 0 author **** 0 source system id *** 0 data source **** 0 title **** 0 date created 2011-09-30 1 facility **** 1 author **** 1 source system id **** 1 data source ***** 1 title use of registered... 1 date created 2011-11-03 2 facility **** 2 author ***** 2 source system id *** 2 data source ******* 2 title request... 2
now, problem, i'm having problems organizing content in gridview. recognizes column names field names. want able to organize information more typical search format such as
date created - "followed title here"
author name
but can't manipulate things because aren't seen fields. overarching question. how use gridview can manipulate based on attributes instead of column names in dataset? have bind grid differently? there sort needs coded (like doc id)? don't care method need able it.
you can use following linq extract data dataset
var results = ds.tables["str"].asenumerable() .where(x => x.field<string>("name") == "qf") .select(y => y.field<string>("str_text"));
i don't think code above best solution. think parsing line line text document give better results. try using treeview code below : recursive adding xml treeview
Comments
Post a Comment