?
Solved

.NET 2.0 XML document

Posted on 2005-03-09
2
Medium Priority
?
381 Views
Last Modified: 2012-05-05
Hi

I have written code to take values out of a database and display an XML document. Although I keep getting this error

Only one top level element is allowed in an XML document. Error processing resource

When i look down at the XML I can see why
<AutoUpdate><Invalid><Value>Invalid</Value></Invalid></AutoUpdate><div id="__asptrace...

But where is the div id= ... coming from. I definitely dont put it there.

Here is my code
Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        'Get Program Request
        Dim program As String = Convert.ToString(Request("x"))

        ' Set the content-type
        Response.ContentType = "text/xml"
        Response.ContentEncoding = Encoding.UTF8

        Dim UpdateData As DataTable = CreateDataSource(program)
        Dim sw As StringWriter = New StringWriter
        Dim writer As XmlTextWriter = New XmlTextWriter(sw)
        'Write Starting elements
        writer.WriteStartElement("AutoUpdate")
        If program = "" Then
            program = "Invalid"
        End If
        writer.WriteStartElement(program)
        If program = "Invalid" Then
            writer.WriteElementString("Value", "Invalid")
        End If
        Dim dbrow As DataRow
        Dim i As Integer = 0
        'Write actual XML data
        For Each dbrow In UpdateData.Rows
            writer.WriteStartElement("item")
            Dim dbcol As DataColumn
            For Each dbcol In UpdateData.Columns
                writer.WriteElementString(dbcol.ColumnName, dbrow.Item(dbcol.Ordinal).ToString)
            Next
            writer.WriteEndElement()
        Next
        'Close starting elements
        writer.WriteEndElement()
        writer.Close()
        Response.Write(sw.ToString)
    End Sub

Thanks
Adam
0
Comment
Question by:adam_pedley
2 Comments
 
LVL 5

Expert Comment

by:vadivhere
ID: 13502811
You're writing all the elements as top ones (that is, parent) that is the error is coming.
you have to have child elements for the parents.

Cheers
Vadivel Kumar
0
 
LVL 12

Accepted Solution

by:
farsight earned 2000 total points
ID: 13504098
Just a guess, but "asptrace" seems to indicate that it's coming from the ASP Tracing feature ... you know, the thing that puts all that tracing information at the end of an HTML page.    Assuming that's it, you'll need to disable tracing.

--- From http://www.dotnet247.com/247reference/msgs/16/82188.aspx ---
You can turn tracing off for the entire application in the web.config file
as shown below.
<configuration>
<trace
enabled="false"
requestlimit="10"
pageoutput="false"
tracemode="SortByTime"
/>
</configuration>

--- To disable tracing on the page, use: ---
<%@ Page Trace="false"%>

--- From http://msdn.microsoft.com/msdnmag/issues/04/09/CuttingEdge/ ---

... you can also turn tracing on and off programmatically at any time:

public void Page_PreRender(object sender, EventArgs e)
{
   // Enable tracing now
   Trace.IsEnabled = true;
}

I'm not sure if you can programmatically turn off tracing soon enough so that there is NO trace information.
The above info applies to .NET 1.1.  Details may differ for .NET 2.0.
0

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I have developed many web applications with asp & asp.net and to add and use a dropdownlist was always a very simple task, but with the new asp.net, setting the value is a bit tricky and its not similar to the old traditional method. So in this a…
Introduction This article shows how to use the open source plupload control to upload multiple images. The images are resized on the client side before uploading and the upload is done in chunks. Background I had to provide a way for user…
As many of you are aware about Scanpst.exe utility which is owned by Microsoft itself to repair inaccessible or damaged PST files, but the question is do you really think Scanpst.exe is capable to repair all sorts of PST related corruption issues?
Enter Foreign and Special Characters Enter characters you can't find on a keyboard using its ASCII code ... and learn how to make a handy reference for yourself using Excel ~ Use these codes in any Windows application! ... whether it is a Micr…
Suggested Courses
Course of the Month12 days, 23 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question