473,322 Members | 1,232 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,322 software developers and data experts.

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.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!

Sep 8 '06 #1
17 3880
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.
Sep 8 '06 #2
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)

Sep 8 '06 #3

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.

Sep 8 '06 #4
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.
Sep 9 '06 #5

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.
Sep 9 '06 #6
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!
Sep 9 '06 #7
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!
Sep 9 '06 #8
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.

Sep 9 '06 #9
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
Sep 9 '06 #10
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
Sep 9 '06 #11
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 misunderstanding.

///Peter

Sep 10 '06 #12
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
Sep 10 '06 #13

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 misunderstanding.

///Peter
Sep 10 '06 #14
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&gt;
&lt;body&gt;
&lt;a&gt;&lt;b&gt;blah&lt;/b&gt;&lt;c&gt;blah&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
Sep 11 '06 #15
pbd22 wrote:
the "<" and the ">" are getting changed into &lt; and &gt;

how do i fix this?
Two possible ways:

* Use DOM, not a string tool.

* Learn at least as much about how to work with XML as native strings
as someone who writes DOMs.

(Guess what, the first of these is easier and more reliable)

Sep 11 '06 #16
hi.

i am new to this and i am trying. As for DOM, I have tried the below:

I am using stringbuilder to build the database values into an
XML doc.
then, to create the DOM, I do the following:
Dim xml As XmlDocument = New XmlDocument
xml.LoadXml(sbhtml.ToString)

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

This returns nothing on the client. I keep getting "undefined". I
appreciate your DOM suggestion, and am learning as i go, but maybe you
could help to provide a solution?

thanks again.

Andy Dingley wrote:
pbd22 wrote:
the "<" and the ">" are getting changed into &lt; and &gt;

how do i fix this?

Two possible ways:

* Use DOM, not a string tool.

* Learn at least as much about how to work with XML as native strings
as someone who writes DOMs.

(Guess what, the first of these is easier and more reliable)
Sep 11 '06 #17
ok, i figured this out.

for others, maybe this will help:

i am working in .NET

I created a search_data.aspx file for the AJAX call.
in the search_data.aspx file, i had the:

<asp:Content ID="Content1" ContentPlaceHolderID="ContentPlaceHolder1"
Runat="Server">

tags wrapping my script. hence, autogenerated HTML
was added after my XML stuff, causing the Junk after XML error.

take out the content tags and you should be good to go.

thanks all for your suggestions along the way.
pbd22 wrote:
hi.

i am new to this and i am trying. As for DOM, I have tried the below:

I am using stringbuilder to build the database values into an
XML doc.
then, to create the DOM, I do the following:
Dim xml As XmlDocument = New XmlDocument
xml.LoadXml(sbhtml.ToString)

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

This returns nothing on the client. I keep getting "undefined". I
appreciate your DOM suggestion, and am learning as i go, but maybe you
could help to provide a solution?

thanks again.

Andy Dingley wrote:
pbd22 wrote:
the "<" and the ">" are getting changed into &lt; and &gt;
>
how do i fix this?
Two possible ways:

* Use DOM, not a string tool.

* Learn at least as much about how to work with XML as native strings
as someone who writes DOMs.

(Guess what, the first of these is easier and more reliable)
Sep 11 '06 #18

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

Similar topics

0
by: Ewan B | last post by:
Hi, I'm using Xerces to parse XML files using SAX2, and am wondering if there is any information as to what exceptions are being thrown when certain validation errors occur. Taking a simple...
2
by: Christophe Vanfleteren | last post by:
Hello, I'm parsing xml that is returned by the Amazon webservices (using their REST interface). Their dev-heavy.xsd has the following entry: <xs:element name="Track"> <xs:complexType>...
6
by: John Ramsden | last post by:
.... when the id 'junk' doesn't exist anywhere in the document, instead of returning 'object'?! I am using Javascript for a drop-down menu, slightly adapted from one by Angus Turnbull (see...
16
by: Terry | last post by:
Hi, This is a newbie's question. I want to preload 4 images and only when all 4 images has been loaded into browser's cache, I want to start a slideshow() function. If images are not completed...
4
by: Mike [MCP VB] | last post by:
Hi, I hope this is the right place to ask. I have an xml file thus: <?xml version="1.0" encoding="UTF-8"?> <Message xmlns="urn:myurl-org:ns2"...
2
by: pbd22 | last post by:
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...
1
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the...
0
by: janakivenk | last post by:
Hello, I am running Oracle 10g R2 in our office. I created the following procedure. It is suppose to access an xml file ( family.xml). The procedure is compiled and when I try to run it, i get the...
2
by: nicky123 | last post by:
Hi everyone, This is a brief description that I have provided for parsing & displaying an XML document using DOM API. Please feel free to post your own comments & views regarding...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.