Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > XML > XML Parsing Error: Junk After Document Element

Reply
Thread Tools

XML Parsing Error: Junk After Document Element

 
 
pbd22
Guest
Posts: n/a
 
      09-08-2006
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.Append(Microsoft.VisualBasic.vbTab)

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!

 
Reply With Quote
 
 
 
 
Joseph Kesselman
Guest
Posts: n/a
 
      09-08-2006
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.
 
Reply With Quote
 
 
 
 
pbd22
Guest
Posts: n/a
 
      09-08-2006
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.StringBuilder

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

For i As Integer = 0 To counter - 1
sbHtml.Append(vbTab)
sbHtml.Append("<user id='")
sbHtml.Append(i)
sbHtml.Append("' siteId='")
sbHtml.Append(siteid(i))
sbHtml.Append("'>")
sbHtml.Append(Environment.NewLine)
sbHtml.Append(vbTab)
sbHtml.Append(vbTab)
sbHtml.Append("<photolocation>")
sbHtml.Append("../uploads/")
sbHtml.Append(uname(i))
sbHtml.Append("/thumbnails/")
sbHtml.Append(pname(i))
sbHtml.Append("</photolocation>")
sbHtml.Append(Environment.NewLine)
sbHtml.Append(vbTab)
sbHtml.Append(vbTab)
sbHtml.Append("<headline>")
sbHtml.Append(headline(i))
sbHtml.Append("</headline>")
sbHtml.Append(Environment.NewLine)
sbHtml.Append(vbTab)
sbHtml.Append(vbTab)
sbHtml.Append("<age>")
sbHtml.Append(CurrentAge(year(i), month(i), day(i)))
sbHtml.Append("</age>")
sbHtml.Append(Environment.NewLine)
sbHtml.Append(vbTab)
sbHtml.Append(vbTab)
sbHtml.Append("<lastactive>")
If LastActive(dlogin(i)) <= 1 Then
sbHtml.Append("24 hours")
End If
If LastActive(dlogin(i)) > 1 and LastActive(dlogin(i)) <= 7
Then
sbHtml.Append(LastActive(dlogin(i)))
sbHtml.Append(" days")
End If
If LastActive(dlogin(i)) >= 7 and LastActive(dlogin(i)) <=
14 Then
sbHtml.Append("week")
End If
If LastActive(dlogin(i)) > 14 and LastActive(dlogin(i)) <=
31 Then
sbHtml.Append("month")
End If
sbHtml.Append("</lastactive>")
sbHtml.Append(Environment.NewLine)
sbHtml.Append(vbTab)
sbHtml.Append(vbTab)
sbHtml.Append("<aboutme>")
sbHtml.Append(aboutme(i))
sbHtml.Append(" ...")
sbHtml.Append("</aboutme>")
sbHtml.Append(Environment.NewLine)
sbHtml.Append(vbTab)
sbHtml.Append("</user>")
sbHtml.Append(Environment.NewLine)
Next

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

 
Reply With Quote
 
Andy Dingley
Guest
Posts: n/a
 
      09-08-2006

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.

 
Reply With Quote
 
pbd22
Guest
Posts: n/a
 
      09-09-2006
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.


 
Reply With Quote
 
pbd22
Guest
Posts: n/a
 
      09-09-2006

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.


 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      09-09-2006
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.Append(Microsoft.VisualBasic.vbTab)
>
> 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!
>

 
Reply With Quote
 
pbd22
Guest
Posts: n/a
 
      09-09-2006
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.StringBuilder

sbhtml.Insert(sbhtml.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(sbhtml.Length, "<user id='")
sbhtml.Insert(sbhtml.Length, i)
sbhtml.Insert(sbhtml.Length, "' siteid='")
sbhtml.Insert(sbhtml.Length, siteid(i))
sbhtml.Insert(sbhtml.Length, "'>")
sbhtml.Insert(sbhtml.Length, "<photolocation>")
sbhtml.Insert(sbhtml.Length, "../uploads/")
sbhtml.Insert(sbhtml.Length, uname(i))
sbhtml.Insert(sbhtml.Length, "/thumbnails/")
sbhtml.Insert(sbhtml.Length, pname(i))
sbhtml.Insert(sbhtml.Length, "</photolocation>")
sbhtml.Insert(sbhtml.Length, "<headline>")
sbhtml.Insert(sbhtml.Length, headline(i))
sbhtml.Insert(sbhtml.Length, "</headline>")
sbhtml.Insert(sbhtml.Length, "<age>")
sbhtml.Insert(sbhtml.Length, CurrentAge(year(i), month(i),
day(i)))
sbhtml.Insert(sbhtml.Length, "</age>")
sbhtml.Insert(sbhtml.Length, "<lastactive>")
If LastActive(dlogin(i)) <= 1 Then
sbhtml.Insert(sbhtml.Length, "24 hours")
End If
If LastActive(dlogin(i)) > 1 And LastActive(dlogin(i)) <= 7
Then
sbhtml.Insert(sbhtml.Length, LastActive(dlogin(i)))
sbhtml.Insert(sbhtml.Length, " days")
End If
If LastActive(dlogin(i)) >= 7 And LastActive(dlogin(i)) <=
14 Then
sbhtml.Insert(sbhtml.Length, "week")
End If
If LastActive(dlogin(i)) > 14 And LastActive(dlogin(i)) <=
31 Then
sbhtml.Insert(sbhtml.Length, "month")
End If
sbhtml.Insert(sbhtml.Length, "</lastactive>")
sbhtml.Insert(sbhtml.Length, "<aboutme>")
sbhtml.Insert(sbhtml.Length, aboutme(i))
sbhtml.Insert(sbhtml.Length, " ...")
sbhtml.Insert(sbhtml.Length, "</aboutme>")
sbhtml.Insert(sbhtml.Length, "</user>")
Next

Context.Response.ContentType = "text/xml"

//NOTE: I have tried both of the following:
Context.Response.Write(sbhtml.Insert(sbhtml.Length ,
sbhtml.ToString))
Context.Response.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.Append(Microsoft.VisualBasic.vbTab)
> >
> > 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!
> >


 
Reply With Quote
 
pbd22
Guest
Posts: n/a
 
      09-09-2006
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.

 
Reply With Quote
 
Peter Flynn
Guest
Posts: n/a
 
      09-10-2006
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to Update/insert an xml element's text----> (<element>text</element>) HANM XML 2 01-29-2008 03:31 PM
XML Parsing Error: junk after document element pbd22 XML 2 03-13-2007 12:04 AM
Different results parsing a XML file with XML::Simple (XML::Sax vs. XML::Parser) Erik Wasser Perl Misc 5 03-05-2006 10:09 PM
Junk after document element Dave19 XML 0 02-08-2006 08:58 PM
Help on including one XML document within another XML document using XML Schemas Tony Prichard XML 0 12-12-2003 03:18 PM



Advertisments