473,395 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Problems Manipulating StringBuilder Output

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/PresentationTi..._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

Mar 13 '07 #1
3 1582

"pbd22" <du*****@gmail.comwrote in message
news:11**********************@s48g2000cws.googlegr oups.com...
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/PresentationTi..._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
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

Mar 13 '07 #2
On Mar 12, 6:19 pm, "Lloyd Sheen" <a...@b.cwrote:
"pbd22" <dush...@gmail.comwrote in message

news:11**********************@s48g2000cws.googlegr oups.com...
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/PresentationTi..._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

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

Mar 13 '07 #3
On Mar 12, 6:19 pm, "Lloyd Sheen" <a...@b.cwrote:
"pbd22" <dush...@gmail.comwrote in message

news:11**********************@s48g2000cws.googlegr oups.com...
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/PresentationTi..._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

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.

Mar 13 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

37
by: Kevin C | last post by:
Quick Question: StringBuilder is obviously more efficient dealing with string concatenations than the old '+=' method... however, in dealing with relatively large string concatenations (ie,...
10
by: Segfahlt | last post by:
I have a fairly simple C# program that just needs to open up a fixed width file, convert each record to tab delimited and append a field to the end of it. The input files are between 300M and...
1
by: Thomas Due | last post by:
Hi, I manage an rather old application in which we have some fairly complex (ugly) Delphi code. This is Delphi 6 we're talking about. Among all this Delphi code there is method for formating a...
3
by: Peeyush81 | last post by:
Hi, I have created a win32 dll with an exported method. extern "C" __declspec(dllexport) void LocateAddress(struct stLocateAddressParam arrAddressParam,int nClientType, LPTSTR outptr); In...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.