XML Parsing Error: Junk After Document Element

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

    XML Parsing Error: Junk After Document Element

    hi.

    i keep getting this error.

    as i understand it, my xml isn't formatted correctly.
    the online errata suggests the standard formatting
    to solve this problem:

    element
    (tab) (tab) element
    (tab) (tab) (tab) element /element
    (tab) (tab) (tab) element /element
    (tab) (tab) /element
    /element

    i attempted to acheive this by using the below line (the xml is coming
    from the server):

    stringbuilder.A ppend(Microsoft .VisualBasic.vb Tab)

    but, I still get the error.

    I have also tried an xml style sheet with style="padding-left:n"
    and this doesnt work.

    i keep getting that darn error.

    when i alert the XML returned from the server, i get all
    elements on the left-most position. no formatting. despite the
    two solutions above.

    i am guessing this comes up a lot. what am i doing wrong?

    thanks!

  • Joseph Kesselman

    #2
    Re: XML Parsing Error: Junk After Document Element

    A well-formed XML document must have one, and only one, top-level
    element. Anything after that element's end-tag will be ignored at best,
    and possibly reported as an error such as the one you're getting here.

    Fix your file/stream/whatever.

    Comment

    • pbd22

      #3
      Re: XML Parsing Error: Junk After Document Element

      Hi.

      Thanks.

      I was hopeful after your comment, and deleted my top-level tag,
      "users", leaving
      just "user" as the top tag. I am still getting that error, tho. My
      string builder on
      the server is as follows (i have tried this with the style sheet
      commented out also) ... maybe you can see something that i am missing?

      Dim sbHtml As New System.Text.Str ingBuilder

      sbHtml.Append(" <?xml version='1.0' standalone='yes '?>")
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(" <?xml-stylesheet type='text/css'
      href='../styles/xml.css'?>")
      sbHtml.Append(E nvironment.NewL ine)

      For i As Integer = 0 To counter - 1
      sbHtml.Append(v bTab)
      sbHtml.Append(" <user id='")
      sbHtml.Append(i )
      sbHtml.Append(" ' siteId='")
      sbHtml.Append(s iteid(i))
      sbHtml.Append(" '>")
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(v bTab)
      sbHtml.Append(v bTab)
      sbHtml.Append(" <photolocation> ")
      sbHtml.Append(" ../uploads/")
      sbHtml.Append(u name(i))
      sbHtml.Append("/thumbnails/")
      sbHtml.Append(p name(i))
      sbHtml.Append(" </photolocation>" )
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(v bTab)
      sbHtml.Append(v bTab)
      sbHtml.Append(" <headline>")
      sbHtml.Append(h eadline(i))
      sbHtml.Append(" </headline>")
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(v bTab)
      sbHtml.Append(v bTab)
      sbHtml.Append(" <age>")
      sbHtml.Append(C urrentAge(year( i), month(i), day(i)))
      sbHtml.Append(" </age>")
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(v bTab)
      sbHtml.Append(v bTab)
      sbHtml.Append(" <lastactive>" )
      If LastActive(dlog in(i)) <= 1 Then
      sbHtml.Append(" 24 hours")
      End If
      If LastActive(dlog in(i)) 1 and LastActive(dlog in(i)) <= 7
      Then
      sbHtml.Append(L astActive(dlogi n(i)))
      sbHtml.Append(" days")
      End If
      If LastActive(dlog in(i)) >= 7 and LastActive(dlog in(i)) <=
      14 Then
      sbHtml.Append(" week")
      End If
      If LastActive(dlog in(i)) 14 and LastActive(dlog in(i)) <=
      31 Then
      sbHtml.Append(" month")
      End If
      sbHtml.Append(" </lastactive>")
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(v bTab)
      sbHtml.Append(v bTab)
      sbHtml.Append(" <aboutme>")
      sbHtml.Append(a boutme(i))
      sbHtml.Append(" ...")
      sbHtml.Append(" </aboutme>")
      sbHtml.Append(E nvironment.NewL ine)
      sbHtml.Append(v bTab)
      sbHtml.Append(" </user>")
      sbHtml.Append(E nvironment.NewL ine)
      Next

      Context.Respons e.ContentType=" text/xml"
      Context.Respons e.Write(sbHtml. ToString)

      Comment

      • Andy Dingley

        #4
        Re: XML Parsing Error: Junk After Document Element


        pbd22 wrote:
        >My string builder
        Don't use string, use a DOM. MSXML is the obvious candidate, and the
        helpfiles are quite good for it.

        Comment

        • pbd22

          #5
          Re: XML Parsing Error: Junk After Document Element

          hi, thanks.

          i have done some reading about MSXML and have even downloaded the
          parser.
          i am still unclear on one item. the XML document i am working with does
          not (nor
          do i want it to) exist as a file. this is an ajax call and the
          stringbuilder i constructed was creating the document out of data
          pulled from the database. the ajax call then grabs the XML text from
          the server and writes it to a hidden DIV at the bottom of the form.

          i am not sure how you see MSXML as a solution to my problem. does it
          pre-format the
          document prior to delivery to the client? I'd appreciate you thinking
          behind this recommendation.

          thanks again.

          Andy Dingley wrote:
          pbd22 wrote:
          >
          My string builder
          >
          Don't use string, use a DOM. MSXML is the obvious candidate, and the
          helpfiles are quite good for it.

          Comment

          • pbd22

            #6
            Re: XML Parsing Error: Junk After Document Element


            OK. this is solved with XmlTextWriter.
            thanks for your help.

            pbd22 wrote:
            hi, thanks.
            >
            i have done some reading about MSXML and have even downloaded the
            parser.
            i am still unclear on one item. the XML document i am working with does
            not (nor
            do i want it to) exist as a file. this is an ajax call and the
            stringbuilder i constructed was creating the document out of data
            pulled from the database. the ajax call then grabs the XML text from
            the server and writes it to a hidden DIV at the bottom of the form.
            >
            i am not sure how you see MSXML as a solution to my problem. does it
            pre-format the
            document prior to delivery to the client? I'd appreciate you thinking
            behind this recommendation.
            >
            thanks again.
            >
            Andy Dingley wrote:
            pbd22 wrote:
            >My string builder
            Don't use string, use a DOM. MSXML is the obvious candidate, and the
            helpfiles are quite good for it.

            Comment

            • Peter Flynn

              #7
              Re: XML Parsing Error: Junk After Document Element

              pbd22 wrote:
              hi.
              >
              i keep getting this error.
              >
              as i understand it, my xml isn't formatted correctly.
              It's nothing to do with formatting. It's the structure of your document.

              Append adds data below the end of a file: this is an error in XML, where
              data must be *inserted* (using the correct element type[s]). At the end
              of the file, once the end-tag has occurred, no further elements are
              permitted.

              ///Peter
              --
              XML FAQ: http://xml.silmaril.ie/

              the online errata suggests the standard formatting
              to solve this problem:
              >
              element
              (tab) (tab) element
              (tab) (tab) (tab) element /element
              (tab) (tab) (tab) element /element
              (tab) (tab) /element
              /element
              >
              i attempted to acheive this by using the below line (the xml is coming
              from the server):
              >
              stringbuilder.A ppend(Microsoft .VisualBasic.vb Tab)
              >
              but, I still get the error.
              >
              I have also tried an xml style sheet with style="padding-left:n"
              and this doesnt work.
              >
              i keep getting that darn error.
              >
              when i alert the XML returned from the server, i get all
              elements on the left-most position. no formatting. despite the
              two solutions above.
              >
              i am guessing this comes up a lot. what am i doing wrong?
              >
              thanks!
              >

              Comment

              • pbd22

                #8
                Re: XML Parsing Error: Junk After Document Element

                Hi Peter,

                thanks. I have tried my string builder using the Insert statement
                but am still getting the same error. What about my current code
                is incorrect? it doesn't sound like it matters if i am using
                stringbuilder
                or xmltextwriter, and i have changed all the appends to inserts. what
                am i missing?

                thank you.

                Dim sbhtml As New System.Text.Str ingBuilder

                sbhtml.Insert(s bhtml.Length, "<?xml version='1.0'
                standalone='yes '?>")
                //NOTE: I have also tried surrounded the below with <usrers>
                </users>

                For i As Integer = 0 To counter - 1
                sbhtml.Insert(s bhtml.Length, "<user id='")
                sbhtml.Insert(s bhtml.Length, i)
                sbhtml.Insert(s bhtml.Length, "' siteid='")
                sbhtml.Insert(s bhtml.Length, siteid(i))
                sbhtml.Insert(s bhtml.Length, "'>")
                sbhtml.Insert(s bhtml.Length, "<photolocation >")
                sbhtml.Insert(s bhtml.Length, "../uploads/")
                sbhtml.Insert(s bhtml.Length, uname(i))
                sbhtml.Insert(s bhtml.Length, "/thumbnails/")
                sbhtml.Insert(s bhtml.Length, pname(i))
                sbhtml.Insert(s bhtml.Length, "</photolocation>" )
                sbhtml.Insert(s bhtml.Length, "<headline> ")
                sbhtml.Insert(s bhtml.Length, headline(i))
                sbhtml.Insert(s bhtml.Length, "</headline>")
                sbhtml.Insert(s bhtml.Length, "<age>")
                sbhtml.Insert(s bhtml.Length, CurrentAge(year (i), month(i),
                day(i)))
                sbhtml.Insert(s bhtml.Length, "</age>")
                sbhtml.Insert(s bhtml.Length, "<lastactiv e>")
                If LastActive(dlog in(i)) <= 1 Then
                sbhtml.Insert(s bhtml.Length, "24 hours")
                End If
                If LastActive(dlog in(i)) 1 And LastActive(dlog in(i)) <= 7
                Then
                sbhtml.Insert(s bhtml.Length, LastActive(dlog in(i)))
                sbhtml.Insert(s bhtml.Length, " days")
                End If
                If LastActive(dlog in(i)) >= 7 And LastActive(dlog in(i)) <=
                14 Then
                sbhtml.Insert(s bhtml.Length, "week")
                End If
                If LastActive(dlog in(i)) 14 And LastActive(dlog in(i)) <=
                31 Then
                sbhtml.Insert(s bhtml.Length, "month")
                End If
                sbhtml.Insert(s bhtml.Length, "</lastactive>")
                sbhtml.Insert(s bhtml.Length, "<aboutme>" )
                sbhtml.Insert(s bhtml.Length, aboutme(i))
                sbhtml.Insert(s bhtml.Length, " ...")
                sbhtml.Insert(s bhtml.Length, "</aboutme>")
                sbhtml.Insert(s bhtml.Length, "</user>")
                Next

                Context.Respons e.ContentType = "text/xml"

                //NOTE: I have tried both of the following:
                Context.Respons e.Write(sbhtml. Insert(sbhtml.L ength,
                sbhtml.ToString ))
                Context.Respons e.Write(sbhtml. ToString))

                Peter Flynn wrote:
                pbd22 wrote:
                hi.

                i keep getting this error.

                as i understand it, my xml isn't formatted correctly.
                >
                It's nothing to do with formatting. It's the structure of your document.
                >
                Append adds data below the end of a file: this is an error in XML, where
                data must be *inserted* (using the correct element type[s]). At the end
                of the file, once the end-tag has occurred, no further elements are
                permitted.
                >
                ///Peter
                --
                XML FAQ: http://xml.silmaril.ie/
                >
                >
                the online errata suggests the standard formatting
                to solve this problem:

                element
                (tab) (tab) element
                (tab) (tab) (tab) element /element
                (tab) (tab) (tab) element /element
                (tab) (tab) /element
                /element

                i attempted to acheive this by using the below line (the xml is coming
                from the server):

                stringbuilder.A ppend(Microsoft .VisualBasic.vb Tab)

                but, I still get the error.

                I have also tried an xml style sheet with style="padding-left:n"
                and this doesnt work.

                i keep getting that darn error.

                when i alert the XML returned from the server, i get all
                elements on the left-most position. no formatting. despite the
                two solutions above.

                i am guessing this comes up a lot. what am i doing wrong?

                thanks!

                Comment

                • pbd22

                  #9
                  Re: XML Parsing Error: Junk After Document Element

                  i believe that i am getting this error
                  because i am sending the results to a DIV
                  inside my HTML? this is not a stand-alone
                  xml file.

                  alas, i am still unsure as the error persists.

                  Comment

                  • Peter Flynn

                    #10
                    Re: XML Parsing Error: Junk After Document Element

                    pbd22 wrote:
                    Hi Peter,
                    >
                    thanks. I have tried my string builder using the Insert statement
                    but am still getting the same error. What about my current code
                    is incorrect? it doesn't sound like it matters if i am using
                    stringbuilder
                    or xmltextwriter, and i have changed all the appends to inserts. what
                    am i missing?
                    I'll leave the answer to a VB expert.
                    You may have better luck posting this in a Microsoft newsgroup
                    if you're stuck using VB.

                    ///Peter

                    Comment

                    • pbd22

                      #11
                      Re: XML Parsing Error: Junk After Document Element

                      hi.

                      so, the changes i made to my code,
                      adding inserts and taking out the appends,
                      was that the solution that you were suggesting?
                      i was a little bit unclear, should the changes
                      i made have worked based on your advice?

                      thanks.

                      Peter Flynn wrote:
                      pbd22 wrote:
                      Hi Peter,

                      thanks. I have tried my string builder using the Insert statement
                      but am still getting the same error. What about my current code
                      is incorrect? it doesn't sound like it matters if i am using
                      stringbuilder
                      or xmltextwriter, and i have changed all the appends to inserts. what
                      am i missing?
                      >
                      I'll leave the answer to a VB expert.
                      You may have better luck posting this in a Microsoft newsgroup
                      if you're stuck using VB.
                      >
                      ///Peter

                      Comment

                      • Peter Flynn

                        #12
                        Re: XML Parsing Error: Junk After Document Element

                        pbd22 wrote:
                        hi.
                        >
                        so, the changes i made to my code,
                        adding inserts and taking out the appends,
                        was that the solution that you were suggesting?
                        i was a little bit unclear, should the changes
                        i made have worked based on your advice?
                        All I said was that you can't add stuff past the end of an XML document.
                        It wasn't clear from your original post that you were using append to
                        *create* the whole document: I thought you were just trying to add stuff
                        to an existing document. Sorry for the misunderstandin g.

                        ///Peter

                        Comment

                        • pbd22

                          #13
                          Re: XML Parsing Error: Junk After Document Element

                          I don't think this is a VB issue, but an XML problem.

                          pbd22 wrote:
                          hi.
                          >
                          so, the changes i made to my code,
                          adding inserts and taking out the appends,
                          was that the solution that you were suggesting?
                          i was a little bit unclear, should the changes
                          i made have worked based on your advice?
                          >
                          thanks.
                          >
                          Peter Flynn wrote:
                          pbd22 wrote:
                          Hi Peter,
                          >
                          thanks. I have tried my string builder using the Insert statement
                          but am still getting the same error. What about my current code
                          is incorrect? it doesn't sound like it matters if i am using
                          stringbuilder
                          or xmltextwriter, and i have changed all the appends to inserts. what
                          am i missing?
                          I'll leave the answer to a VB expert.
                          You may have better luck posting this in a Microsoft newsgroup
                          if you're stuck using VB.

                          ///Peter

                          Comment

                          • pbd22

                            #14
                            Re: XML Parsing Error: Junk After Document Element


                            oh. ok. i see. no, i am programatically creating the XML
                            from database values, then writing the results via AJAX
                            to a DIV on my form. It lives there while the user's session
                            lasts. the XML is never in a "file" per se.

                            so, i guess i am back to the drawing board.

                            thanks for trying.

                            Peter Flynn wrote:
                            pbd22 wrote:
                            hi.

                            so, the changes i made to my code,
                            adding inserts and taking out the appends,
                            was that the solution that you were suggesting?
                            i was a little bit unclear, should the changes
                            i made have worked based on your advice?
                            >
                            All I said was that you can't add stuff past the end of an XML document.
                            It wasn't clear from your original post that you were using append to
                            *create* the whole document: I thought you were just trying to add stuff
                            to an existing document. Sorry for the misunderstandin g.
                            >
                            ///Peter

                            Comment

                            • pbd22

                              #15
                              Re: XML Parsing Error: Junk After Document Element

                              hi. a bit of an update:

                              i am getting a sense that my error is sum'd up as follows:

                              i am sending my xml via stringbuilder from the server like this:

                              <header>
                              <body>
                              <a>
                              <b>blah</b>
                              <c>blah</c>
                              </a>
                              </body>
                              </header>

                              but, it is turning up on the client like this:

                              &lt;header&g t;
                              &lt;body&gt;
                              &lt;a&gt;&lt;b& gt;blah&lt;/b&gt;&lt;c&gt;b lah&lt;/c&gt;&lt;/a&gt;
                              &lt;/body&gt;
                              &lt;/header&gt;

                              the "<" and the ">" are getting changed into &lt; and &gt;

                              how do i fix this?


                              pbd22 wrote:
                              I don't think this is a VB issue, but an XML problem.
                              >
                              pbd22 wrote:
                              hi.

                              so, the changes i made to my code,
                              adding inserts and taking out the appends,
                              was that the solution that you were suggesting?
                              i was a little bit unclear, should the changes
                              i made have worked based on your advice?

                              thanks.

                              Peter Flynn wrote:
                              pbd22 wrote:
                              Hi Peter,

                              thanks. I have tried my string builder using the Insert statement
                              but am still getting the same error. What about my current code
                              is incorrect? it doesn't sound like it matters if i am using
                              stringbuilder
                              or xmltextwriter, and i have changed all the appends to inserts. what
                              am i missing?
                              >
                              I'll leave the answer to a VB expert.
                              You may have better luck posting this in a Microsoft newsgroup
                              if you're stuck using VB.
                              >
                              ///Peter

                              Comment

                              Working...