Problems Manipulating StringBuilder Output

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • pbd22

    #1

    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.Str ingBuilder
    sbhtml.Append(" <Some XML Tag>")
    etc...
    Context.Respons e.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><uplo ad><filename>So meVideo.gvi</filename><bytes sent>0</
    bytessent><file size>12444894</filesize><perce nt>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

  • Lloyd Sheen

    #2
    Re: Problems Manipulating StringBuilder Output


    "pbd22" <dushkin@gmail. comwrote in message
    news:1173744758 .854047.320670@ s48g2000cws.goo glegroups.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.Str ingBuilder
    sbhtml.Append(" <Some XML Tag>")
    etc...
    Context.Respons e.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><upl oad><filename>S omeVideo.gvi</filename><bytes sent>0</
    bytessent><file size>12444894</filesize><perce nt>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

    Comment

    • pbd22

      #3
      Re: Problems Manipulating StringBuilder Output

      On Mar 12, 6:19 pm, "Lloyd Sheen" <a...@b.cwrot e:
      "pbd22" <dush...@gmail. comwrote in message
      >
      news:1173744758 .854047.320670@ s48g2000cws.goo glegroups.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.Str ingBuilder
      sbhtml.Append(" <Some XML Tag>")
      etc...
      Context.Respons e.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><uplo ad><filename>So meVideo.gvi</filename><bytes sent>0</
      bytessent><file size>12444894</filesize><perce nt>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

      Comment

      • pbd22

        #4
        Re: Problems Manipulating StringBuilder Output

        On Mar 12, 6:19 pm, "Lloyd Sheen" <a...@b.cwrot e:
        "pbd22" <dush...@gmail. comwrote in message
        >
        news:1173744758 .854047.320670@ s48g2000cws.goo glegroups.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.Str ingBuilder
        sbhtml.Append(" <Some XML Tag>")
        etc...
        Context.Respons e.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><uplo ad><filename>So meVideo.gvi</filename><bytes sent>0</
        bytessent><file size>12444894</filesize><perce nt>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.

        Comment

        Working...