Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: RE: XML --> StreamWriter --> String Variables - SOLVED- FINALLY


Message #1 by Scott Watermasysk <swatermasysk@C...> on Tue, 8 May 2001 11:27:35 -0400
The bonehead (me) finally figured it out.



When trying to read the remote XML file, I had been using a Function called

GetXML that reads a remote file and converts its contents to a string. I was

then having problems working with this string (although according to the

.Net documentation, it is possible...I still don't get it...). 



Anyway, I was responding to a post by Doug Steven's at

http://www.aspnextgen.com (great site), when I commented that a lot of

samples were using the FileStream and StreamReader Object.



I decided to try to modify my GetXML function, to simply return the Stream

Object, and this seams to be the ticket. 



I changed the GetXML function from:

	Function GetXML(strURI As String) As String

		Dim objURI As URI = New URI(strURI)

		Dim objWebRequest As WebRequest 

WebRequestFactory.Create(objURI)

		Dim objWebResponse As WebResponse 

objWebRequest.GetResponse()

		Dim objStream As Stream = objWebResponse.GetResponseStream()

		Dim objStreamReader As StreamReader = New

StreamReader(objStream)

		Dim strHTML As String = objStreamReader.ReadToEnd

		GetXML = strHTML

	End Function



To a function called GetStream, which of course returns the Stream:

	Function GetStream(strURI As String) As StreamReader

		Dim objURI As URI = New URI(strURI)

		Dim objWebRequest As WebRequest 

WebRequestFactory.Create(objURI)

		Dim objWebResponse As WebResponse 

objWebRequest.GetResponse()

		Dim objStream As Stream = objWebResponse.GetResponseStream()

		Dim objStreamReader As StreamReader = New

StreamReader(objStream)

		GetStream = objStreamReader

	End Function



Many thanks to all who read and replied to my posts. It was a big help to

know that I was moving in the right direction.



Regards,

Scott



Full Documentation:

<%@ Page Language="VB" Debug = "False" Trace = "False"%>

<%@ Import Namespace="System.Net" %>

<%@ Import Namespace="System.IO" %>

<%@ Import Namespace="System.XML" %>

<%@ Import Namespace="System.Data" %>

<SCRIPT Language="VB" Option="Explicit" runat="server">		

	Sub Page_Load(Src as object, E as EventArgs)

	

	Dim proxyObject as DefaultControlObject

	proxyObject = new DefaultControlObject("ServerName",80)

	GlobalProxySelection.Select = proxyObject



	Dim SR as StreamReader 

GetStream("http://p.moreover.com/cgi-local/page?index_topstories+xml")

	Dim ds as DataSet = new DataSet()  

		

	ds.ReadXml(SR)



 	dg.DataSource = ds.Tables(0).defaultview

	dg.DataBind()	

	End Sub

	

	Function GetStream(strURI As String) As StreamReader

		Dim objURI As URI = New URI(strURI)

		Dim objWebRequest As WebRequest 

WebRequestFactory.Create(objURI)

		Dim objWebResponse As WebResponse 

objWebRequest.GetResponse()

		Dim objStream As Stream = objWebResponse.GetResponseStream()

		Dim objStreamReader As StreamReader = New

StreamReader(objStream)

		GetStream = objStreamReader

	End Function	

</SCRIPT>


  Return to Index