?
Solved

.NET 2.0 XML document

Posted on 2005-03-09
2
Medium Priority
?
355 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In this Article, I will provide a few tips in problem and solution manner. Opening an ASPX page in Visual studio 2003 is very slow. To make it fast, please do follow below steps:   Open the Solution/Project. Right click the ASPX file to b…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
Suggested Courses

764 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