Need Help Manipulating Strings (Remove/Replace)

  • Thread starter Thread starter pbd22
  • Start date Start date
P

pbd22

Hi.

How Do I "UPDATE" a previously created string?
I have a problem where an XML string created in
an event handler fails because the string doesn't "UPDATE"
each time the event hanlder fires, but "APPENDS",
creating lots of repetition in the XML:

Quote:
XML Parsing Error: junk after document element

Location: http://localhost:5223/Presentation/set/progress.aspx
Line Number 1, Column 191:<?xml version='1.0' encoding='ISO-8859-1'?
<uploads><upload><filename>SomeVideo.gvi</filename><bytessent>0</

bytessent><filesize>12444894</filesize><percent>0</percent></upload></
uploads><?xml version='1.0' encoding='ISO-8859-1'?> ...

and, the built string inside the event handler method
looks like this:

Code:

Dim sbhtml As New System.Text.StringBuilder
sbhtml.Append("<Some XML Tag>")
etc...
Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)

So, how do I update the string each time the event handler
fires, not append more xml to the recently created string?

Thanks.
Peter
 
pbd22 said:
How Do I "UPDATE" a previously created string?

You can't. Strings are immutable.

All you can do is create a new string which has the appropriate
changes.
I have a problem where an XML string created in
an event handler fails because the string doesn't "UPDATE"
each time the event hanlder fires, but "APPENDS",
creating lots of repetition in the XML:

Code:

Dim sbhtml As New System.Text.StringBuilder
sbhtml.Append("<Some XML Tag>")
etc...
Context.Response.ContentType = "text/xml"
Response.Write(sbhtml.ToString)

Well yes, if you write to the response stream each time, it *will*
effectively append it.

You need to decide what you want to write and *then* write it. You
can't "unwrite" bits of the response.
 
You can't. Strings are immutable.

All you can do is create a new string which has the appropriate
changes.


Well yes, if you write to the response stream each time, it *will*
effectively append it.

You need to decide what you want to write and *then* write it. You
can't "unwrite" bits of the response.


Thanks Jon,

It isn't a question of not knowing what I want to send. The probelm is
that the program has to send a lot as the upload data from the server
updates.

So, what would you suggest? I am returning the results of a progress
meter to the client. Depending on filesize, the response stream will
get at least 100 writes (ie - 1%, 2%, 3%, 3%, 3%, 4%, 5%, etc...). If
the client is going to throw an XML parser error every time lots of
XML
strings try to make their way from the server, then this method isn't
going
to work.

What will allow me to send well-formed XML from the server in the
manner
discussed above?

Thanks a alot.
 
pbd22 said:
It isn't a question of not knowing what I want to send. The probelm is
that the program has to send a lot as the upload data from the server
updates.

So, what would you suggest? I am returning the results of a progress
meter to the client. Depending on filesize, the response stream will
get at least 100 writes (ie - 1%, 2%, 3%, 3%, 3%, 4%, 5%, etc...). If
the client is going to throw an XML parser error every time lots of
XML strings try to make their way from the server, then this method isn't
going to work.

What will allow me to send well-formed XML from the server in the
manner discussed above?

You can't do progress messages that way with HTTP. It's not that kind
of protocol.

I would suggest that you send the client back a page which polls back
to the server show the current progress.
 
You can't do progress messages that way with HTTP. It's not that kind
of protocol.

I would suggest that you send the client back a page which polls back
to the server show the current progress.

I guess I am a little confused as to how the upload data should be
coming from the server. I understand client polling loops (that
actually is what I was trying to do) but I am unclear as to how the
response text or xml should be returned to the client. Do you have
more specific examples of this?

Thanks very much.
 
pbd22 said:
I guess I am a little confused as to how the upload data should be
coming from the server. I understand client polling loops (that
actually is what I was trying to do) but I am unclear as to how the
response text or xml should be returned to the client. Do you have
more specific examples of this?

Each time the client polls, just return the current progress (1%, 5% or
whatever).
 
Each time the client polls, just return the current progress (1%, 5% or
whatever).


Right, thanks. That is what I "thought" I was doing with the XML
style stringbuilder. I guess this is kind of a newbie question but,
how do I return the updated data at the moment the client polling loop
requests it? The only way I can think of doing this is to save the
event handler's progress variables in some sort of global class
that gets accessed by a different aspx form during its Page_Load
method.
Then, the client-side polling loop calls the new aspx page and
response.write
inside its Page_Load method returns the current progress (whatever
that may be).

Is this what you were thinking when you said "Each time the client
polls, just return the current progress (1%, 5% or whatever)."

thanks again.
 
pbd22 said:
Right, thanks. That is what I "thought" I was doing with the XML
style stringbuilder. I guess this is kind of a newbie question but,
how do I return the updated data at the moment the client polling loop
requests it? The only way I can think of doing this is to save the
event handler's progress variables in some sort of global class
that gets accessed by a different aspx form during its Page_Load
method.

You'll need to have the actual "work" being done in a different thread,
and saving information to the client's session. Then when the client
polls, use the information in the session to give the current progress.

Basically what you were saying, but using the session instead of a
global variable.
 
Back
Top