Wrox Home  
Search P2P Archive for: Go

  Return to Index  

aspx thread: XML --> StreamWriter --> String Variables


Message #1 by Scott Watermasysk <swatermasysk@C...> on Mon, 7 May 2001 10:50:06 -0400
Hello All,



I have a function that reads a remote XML file and converts it to a string.

I can then view this string in my browser.



Is it possible to manipulate this string the same way I would with a local

XML file?



I know I could use StreamWriter to write a local copy of the XML file, but I

was hoping do this simply from the string variable? Does this make Sense? Is

it possible?



In short, what I am trying to do is read a remote XML file, and display its

contents in a table or datalist....etc.



Thanks for any help/advice/guidance.



Regards,

Scott

Message #2 by Richard Huang <rhuang@l...> on Mon, 7 May 2001 14:50:31 -0700
Hi, Scott,



If you are using MicroSoft system, then you can read the local XML file to

DOM.  After it's in DOM, then you can parse it without any problem.



The VB code is like the following:



	Set objReq = Server.CreateObject("Microsoft.XMLDOM")

	objReq.async=false

	objReq.load(Server.MapPath("test1.xml"))



Hopefully that helps.



Richard Huang

xxx-xxx-xxxx

LifeMap Communications, Inc.

201 N. Civic Drive Suite 239

Walnut Creek CA, 94596



-----Original Message-----

From: Scott Watermasysk [mailto:swatermasysk@C...]

Sent: Monday, May 07, 2001 7:50 AM

To: ASP+

Subject: [aspx] XML --> StreamWriter --> String Variables





Hello All,



I have a function that reads a remote XML file and converts it to a string.

I can then view this string in my browser.



Is it possible to manipulate this string the same way I would with a local

XML file?



I know I could use StreamWriter to write a local copy of the XML file, but I

was hoping do this simply from the string variable? Does this make Sense? Is

it possible?



In short, what I am trying to do is read a remote XML file, and display its

contents in a table or datalist....etc.



Thanks for any help/advice/guidance.



Regards,

Scott

Message #3 by Scott Watermasysk <swatermasysk@C...> on Mon, 7 May 2001 18:01:28 -0400
Thanks, but I am trying to read a remote file.



-----Original Message-----

From: Richard Huang [mailto:rhuang@l...]

Sent: Monday, May 07, 2001 5:51 PM

To: ASP+

Subject: [aspx] RE: XML --> StreamWriter --> String Variables





Hi, Scott,



If you are using MicroSoft system, then you can read the local XML file to

DOM.  After it's in DOM, then you can parse it without any problem.



The VB code is like the following:



	Set objReq = Server.CreateObject("Microsoft.XMLDOM")

	objReq.async=false

	objReq.load(Server.MapPath("test1.xml"))



Hopefully that helps.



Richard Huang

xxx-xxx-xxxx

LifeMap Communications, Inc.

201 N. Civic Drive Suite 239

Walnut Creek CA, 94596



-----Original Message-----

From: Scott Watermasysk [mailto:swatermasysk@C...]

Sent: Monday, May 07, 2001 7:50 AM

To: ASP+

Subject: [aspx] XML --> StreamWriter --> String Variables





Hello All,



I have a function that reads a remote XML file and converts it to a string.

I can then view this string in my browser.



Is it possible to manipulate this string the same way I would with a local

XML file?



I know I could use StreamWriter to write a local copy of the XML file, but I

was hoping do this simply from the string variable? Does this make Sense? Is

it possible?



In short, what I am trying to do is read a remote XML file, and display its

contents in a table or datalist....etc.



Thanks for any help/advice/guidance.



Regards,

Scott

Message #4 by Richard Huang <rhuang@l...> on Mon, 7 May 2001 16:14:41 -0700
Scott,



Let me clear the question.  So you can read a remote XML and convert to a

string, and then you wanner manipulate this string on the fly instead of

writing this string to a local XML file.



If it is your question, then you can use the following code to put this

string into DOM object:



	strXML=whatever the string you get from the remote XML

	Set objReq = Server.CreateObject("Microsoft.XMLDOM")

	objReq.async=false

	'the loadXML method load the string containing the XML file 

	objReq.loadXML(strXML)



Hopefully i understand your question this time. ^-^



Richard







-----Original Message-----

From: Scott Watermasysk [mailto:swatermasysk@C...]

Sent: Monday, May 07, 2001 3:01 PM

To: ASP+

Subject: [aspx] RE: XML --> StreamWriter --> String Variables





Thanks, but I am trying to read a remote file.



-----Original Message-----

From: Richard Huang [mailto:rhuang@l...]

Sent: Monday, May 07, 2001 5:51 PM

To: ASP+

Subject: [aspx] RE: XML --> StreamWriter --> String Variables





Hi, Scott,



If you are using MicroSoft system, then you can read the local XML file to

DOM.  After it's in DOM, then you can parse it without any problem.



The VB code is like the following:



	Set objReq = Server.CreateObject("Microsoft.XMLDOM")

	objReq.async=false

	objReq.load(Server.MapPath("test1.xml"))



Hopefully that helps.



Richard Huang

xxx-xxx-xxxx

LifeMap Communications, Inc.

201 N. Civic Drive Suite 239

Walnut Creek CA, 94596



-----Original Message-----

From: Scott Watermasysk [mailto:swatermasysk@C...]

Sent: Monday, May 07, 2001 7:50 AM

To: ASP+

Subject: [aspx] XML --> StreamWriter --> String Variables





Hello All,



I have a function that reads a remote XML file and converts it to a string.

I can then view this string in my browser.



Is it possible to manipulate this string the same way I would with a local

XML file?



I know I could use StreamWriter to write a local copy of the XML file, but I

was hoping do this simply from the string variable? Does this make Sense? Is

it possible?



In short, what I am trying to do is read a remote XML file, and display its

contents in a table or datalist....etc.



Thanks for any help/advice/guidance.



Regards,

Scott

Message #5 by Scott Watermasysk <swatermasysk@C...> on Tue, 8 May 2001 09:40:54 -0400
Richard,



Thanks again for the reply. Sorry if I sounded rude. I know this is probably

a simple thing I am missing, but I just can't seem to get it too work.



Instead of using the set obj....(by the way, I didn't think we had to use

Set in ASP.Net), I used

	 Dim xmlDoc as XmlDocument = new XmlDocument()

	 xmlDoc.LoadXML(sXML) 'sXML is a string of an XML Document (see

function below)

	 myXml.Document = xmldoc



Using this and the GetXML function (below) I was able to view my XML

document using the <ASP:XML id="myXML" runat "Server" /> control.



However, what I would really like to do is bind this XML file to a datagrid.

But I can't seem to get it too work. I also tried to use the dataset's

readxml method. (ds.ReadXML(sXML)). 



Here is the code from my second (really it is closer to 40....) try. This

seems to work, except it gives me an error with on the dg.DataSource 

ds.Tables(0) line. After this I just set the <asp:DataGrid id="dg ...etc. />

I know this part is OK because I am able to read a local file with it no

problem. However, what I am trying to do is build a system to read through

moreover's 1300 news feeds, so writing a local file with the StreamWriter

and then reading it with the FileStream would create too many files.

Ultimately I want to read the XML file, write the HTML, and then cache it

for an hour or so. This way only the feeds that get used will be taking up

system resources.



Thanks again.

Scott



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

<%@ 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)

	

	'I need this to get through our Proxy, comment it out if you don't

	Dim proxyObject as DefaultControlObject

	proxyObject = new DefaultControlObject("ProxyServerName",80)

	GlobalProxySelection.Select = proxyObject



	Dim sXML as String 

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



	Dim ds as DataSet = new DataSet()  

		

	ds.ReadXml(sXML)



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

	dg.DataBind()

	

	End Sub

	

	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	

</SCRIPT>



-----Original Message-----

From: Richard Huang [mailto:rhuang@l...]

Sent: Monday, May 07, 2001 5:51 PM

To: ASP+

Subject: [aspx] RE: XML --> StreamWriter --> String Variables





Hi, Scott,



If you are using MicroSoft system, then you can read the local XML file to

DOM.  After it's in DOM, then you can parse it without any problem.



The VB code is like the following:



	Set objReq = Server.CreateObject("Microsoft.XMLDOM")

	objReq.async=false

	objReq.load(Server.MapPath("test1.xml"))



Hopefully that helps.



Richard Huang

xxx-xxx-xxxx

LifeMap Communications, Inc.

201 N. Civic Drive Suite 239

Walnut Creek CA, 94596



-----Original Message-----

From: Scott Watermasysk [mailto:swatermasysk@C...]

Sent: Monday, May 07, 2001 7:50 AM

To: ASP+

Subject: [aspx] XML --> StreamWriter --> String Variables





Hello All,



I have a function that reads a remote XML file and converts it to a string.

I can then view this string in my browser.



Is it possible to manipulate this string the same way I would with a local

XML file?



I know I could use StreamWriter to write a local copy of the XML file, but I

was hoping do this simply from the string variable? Does this make Sense? Is

it possible?



In short, what I am trying to do is read a remote XML file, and display its

contents in a table or datalist....etc.



Thanks for any help/advice/guidance.



Regards,

Scott




  Return to Index