Problems Manipulating StringBuilder Output

P

pbd22

Hi.

I have an event handler in VB.NET that gets called several times.
The output of the event handler is XML that is being called by
an xmlhttp request from the client.

I am using a stringbuilder to create an XML document every time
the event handler gets fired. Each tag is appended like so:

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

The problem is that the XML document gets recreated and appended every
time the event handler fires and I get a junk error after the first
document's parent tag is closed:

XML Parsing Error: junk after document element

Location: http://localhost:5223/PresentationTier/set/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'?> ...

SO: How do I prevent this? How Do I "UPDATE" the XML document every
time the event handler fires and not "APPPEND" a new document to the
recently created one?

Thanks.
Peter
 
L

Lloyd Sheen

pbd22 said:
Hi.

I have an event handler in VB.NET that gets called several times.
The output of the event handler is XML that is being called by
an xmlhttp request from the client.

I am using a stringbuilder to create an XML document every time
the event handler gets fired. Each tag is appended like so:

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

The problem is that the XML document gets recreated and appended every
time the event handler fires and I get a junk error after the first
document's parent tag is closed:

XML Parsing Error: junk after document element

Location: http://localhost:5223/PresentationTier/set/set_progress.aspx
Line Number 1, Column 191:<?xml version='1.0' encoding='ISO-8859-1'?
bytessent><filesize>12444894</filesize><percent>0</percent></upload></
uploads><?xml version='1.0' encoding='ISO-8859-1'?> ...

SO: How do I prevent this? How Do I "UPDATE" the XML document every
time the event handler fires and not "APPPEND" a new document to the
recently created one?

Thanks.
Peter

Why not use the built in classes for building XML. If the docs are not too
large use the DOM which is very easy to use. You can create a DOM and then
update it using the API. Then you can write the XML to a file for
consumption by the aspx page.

Lloyd Sheen
 
P

pbd22

Why not use the built in classes for building XML. If the docs are not too
large use the DOM which is very easy to use. You can create a DOM and then
update it using the API. Then you can write the XML to a file for
consumption by the aspx page.

Lloyd Sheen


Thanks Lloyd.

Very open to other approaches - this is just the one that I have
been working with. Would you mind pointing me towards a link
that shows me what you mean or dumping some code here for
a quick and dirty demonstration?

Thanks a buch.
peter
 
P

pbd22

Why not use the built in classes for building XML. If the docs are not too
large use the DOM which is very easy to use. You can create a DOM and then
update it using the API. Then you can write the XML to a file for
consumption by the aspx page.

Lloyd Sheen


one more thing... does the fact that this XML file is intended for the
"client", not the "aspx" page matter? this is a response to an xmlhttp
request - the XML is not meant to exist beyond the moment the event
handler is called.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top