load xml file in a rich text box from a remote server to vb.net form -
i have windows app in vb.net , trying read xml file server(http://dev2010.abc.com/abc.xml).i able read abc.xml . now have requirement show abc.xml in rich text box in vb.net , have show node , value in combobox. able directory(suppose file in c:/abc.xml) please suggest me way way load xml file server in rich tex box , there show nodes , corresponding value in combobox , display output in textbox..
code in vb .net
imports system.xml imports system.io public class form1 inherits system.windows.forms.form region " windows form designer generated code " public sub new() mybase.new() initializecomponent() end sub protected overloads overrides sub dispose(byval disposing boolean) if disposing if not (components nothing) components.dispose() end if end if mybase.dispose(disposing) end sub friend withevents txtfile system.windows.forms.textbox friend withevents txtresults system.windows.forms.textbox friend withevents btnlist system.windows.forms.button friend withevents txttagname system.windows.forms.textbox friend withevents lblfile system.windows.forms.label friend withevents lbltag system.windows.forms.label friend withevents combobox1 system.windows.forms.combobox friend withevents dg_ipinfo system.windows.forms.datagridview private components system.componentmodel.container <system.diagnostics.debuggerstepthrough()> private sub initializecomponent() me.lbltag = new system.windows.forms.label me.txtresults = new system.windows.forms.textbox me.btnlist = new system.windows.forms.button me.lblfile = new system.windows.forms.label me.txtfile = new system.windows.forms.textbox me.txttagname = new system.windows.forms.textbox me.combobox1 = new system.windows.forms.combobox me.dg_ipinfo = new system.windows.forms.datagridview ctype(me.dg_ipinfo, system.componentmodel.isupportinitialize).begininit() me.suspendlayout() ' 'lbltag ' me.lbltag.location = new system.drawing.point(47, 30) me.lbltag.name = "lbltag" me.lbltag.size = new system.drawing.size(32, 16) me.lbltag.tabindex = 4 me.lbltag.text = "tag" ' 'txtresults ' me.txtresults.location = new system.drawing.point(496, 239) me.txtresults.multiline = true me.txtresults.name = "txtresults" me.txtresults.scrollbars = system.windows.forms.scrollbars.both me.txtresults.size = new system.drawing.size(200, 309) me.txtresults.tabindex = 3 ' 'btnlist ' me.btnlist.location = new system.drawing.point(228, 30) me.btnlist.name = "btnlist" me.btnlist.size = new system.drawing.size(40, 23) me.btnlist.tabindex = 1 me.btnlist.text = "list" ' 'lblfile ' me.lblfile.location = new system.drawing.point(82, 217) me.lblfile.name = "lblfile" me.lblfile.size = new system.drawing.size(100, 19) me.lblfile.tabindex = 5 me.lblfile.text = "file" me.lblfile.textalign = system.drawing.contentalignment.middlecenter ' 'txtfile ' me.txtfile.location = new system.drawing.point(12, 239) me.txtfile.multiline = true me.txtfile.name = "txtfile" me.txtfile.scrollbars = system.windows.forms.scrollbars.both me.txtfile.size = new system.drawing.size(224, 309) me.txtfile.tabindex = 2 ' 'txttagname ' me.txttagname.location = new system.drawing.point(100, 30) me.txttagname.name = "txttagname" me.txttagname.size = new system.drawing.size(104, 20) me.txttagname.tabindex = 0 me.txttagname.text = "status" ' 'combobox1 ' me.combobox1.formattingenabled = true me.combobox1.location = new system.drawing.point(496, 179) me.combobox1.name = "combobox1" me.combobox1.size = new system.drawing.size(200, 21) me.combobox1.tabindex = 6 ' 'dg_ipinfo ' me.dg_ipinfo.backgroundcolor = system.drawing.systemcolors.controllightlight me.dg_ipinfo.columnheadersheightsizemode = system.windows.forms.datagridviewcolumnheadersheightsizemode.autosize me.dg_ipinfo.location = new system.drawing.point(12, 73) me.dg_ipinfo.name = "dg_ipinfo" me.dg_ipinfo.size = new system.drawing.size(461, 127) me.dg_ipinfo.tabindex = 7 ' 'form1 ' me.autoscalebasesize = new system.drawing.size(5, 13) me.clientsize = new system.drawing.size(833, 560) me.controls.add(me.dg_ipinfo) me.controls.add(me.combobox1) me.controls.add(me.txtresults) me.controls.add(me.txttagname) me.controls.add(me.lbltag) me.controls.add(me.btnlist) me.controls.add(me.lblfile) me.controls.add(me.txtfile) me.name = "form1" me.text = "getelementsbytagname" ctype(me.dg_ipinfo, system.componentmodel.isupportinitialize).endinit() me.resumelayout(false) me.performlayout() end sub private xml_doc xmldocument private sub form1_load(byval sender system.object, byval e system.eventargs) handles mybase.load dim resolver new xmlurlresolver() dim myuri new uri("http://dev2010.abc.com/abc.xml") ' dim myuri new uri("http://localhost/test_abc/abc.xml") 'dim s1 string = directcast(resolver.getentity(myuri, nothing, gettype(string)), string) dim s stream = directcast(resolver.getentity(myuri, nothing, gettype(stream)), stream) dim xmltextreader new xmltextreader(s) dim xdoc1 new xmldatadocument() xdoc1.dataset.readxml(xmltextreader, xmlreadmode.auto) dim ds dataset = xdoc1.dataset 'dg_liverates.datasource = xdoc1.dataset; 'dataset ds = new dataset(); dim dt datatable = ds.tables(0) dg_ipinfo.datasource = dt dim file_name string = datasubdirectory() & "\abc.xml" 'dim results string txtfile.text = getfilecontents(file_name) xml_doc = new xmldocument() xml_doc.load(file_name) combobox1.items.add("status") combobox1.items.add("ip") combobox1.items.add("countrycode") combobox1.items.add("countryname") combobox1.items.add("regioncode") combobox1.items.add("regionname") combobox1.items.add("city") combobox1.items.add("zipcode") combobox1.items.add("latitude") combobox1.items.add("longitude") end sub private sub btnlist_click(byval sender system.object, byval e system.eventargs) handles btnlist.click 'dim xml_node_list xmlnodelist 'dim xml_node xmlnode ' dim results string 'xml_node_list = xml_doc.getelementsbytagname(txttagname.text) 'for each xml_node in xml_node_list 'results = results & xml_node.innertext & vbcrlf 'combobox1.items.add("s") 'next xml_node 'txtresults.text = results end sub private sub form1_resize(byval sender object, byval e system.eventargs) handles mybase.resize dim wid integer dim hgt integer wid = clientsize.width \ 2 hgt = clientsize.height - txtfile.location.y if hgt < 10 hgt = 10 lblfile.setbounds(0, 0, wid, lblfile.size.height) txtfile.setbounds(0, txtfile.location.y, wid, hgt) lbltag.setbounds(wid, 0, lbltag.size.width, lbltag.size.height) txtresults.setbounds(wid, txtfile.location.y, wid, hgt) btnlist.setbounds(clientsize.width - btnlist.size.width, 0, btnlist.size.width, btnlist.size.height) wid = btnlist.location.x - lbltag.location.x - lbltag.size.width - 10 if wid < 10 wid = 10 txttagname.setbounds(lbltag.location.x + lbltag.size.width, 0, wid, txttagname.size.height) end sub private sub txtfile_textchanged(byval sender system.object, byval e system.eventargs) handles txtfile.textchanged end sub private sub txtresults_textchanged(byval sender system.object, byval e system.eventargs) handles txtresults.textchanged end sub private sub txttagname_textchanged(byval sender system.object, byval e system.eventargs) handles txttagname.textchanged end sub private sub combobox1_selectedvaluechanged(byval sender object, byval e system.eventargs) handles combobox1.selectedvaluechanged dim xml_node_list xmlnodelist dim xml_node xmlnode dim results string xml_node_list = xml_doc.getelementsbytagname(txttagname.text) each xml_node in xml_node_list results = results & xml_node.innertext & vbcrlf next xml_node txtresults.text = results end sub private sub combobox1_selectedindexchanged(byval sender system.object, byval e system.eventargs) handles combobox1.selectedindexchanged dim xml_node_list xmlnodelist dim xml_node xmlnode dim results1 string dim results string results1 = combobox1.text xml_node_list = xml_doc.getelementsbytagname(results1) each xml_node in xml_node_list results = results & xml_node.innertext & vbcrlf next xml_node txtresults.text = results end sub private sub dg_ipinfo_cellcontentclick(byval sender system.object, byval e system.windows.forms.datagridviewcelleventargs) handles dg_ipinfo.cellcontentclick end sub private sub lblfile_click(byval sender system.object, byval e system.eventargs) handles lblfile.click end sub end class
please suggest me way.
me.lbltag.location = new system.drawing.point(47, 30) me.lbltag.name = "lbltag" me.lbltag.size = new system.drawing.size(32, 16) me.lbltag.tabindex = 4 me.lbltag.text = "tag"
Comments
Post a Comment