locked
Token StartElement in state Epilog would result in an invalid XML document RRS feed

  • Question

  • when trying to dataset.writexml(strXMLFile) I get this error: Token StartElement in state Epilog would result in an invalid XML document.  Please can someone help me, I really am stuck and have no idea why certain XML Files work while others dont.  I've added ASP .NET as a user for the xml files with modify permissions so I know this isn't the prob.  I can read the XML, create a new row but as soon as I try to write the XML it bombs out.

    I would be most appreciative if someone could tell me why this happens as I am spent on this prob (never completely)

     

    Regards

    Eric Cann

     

     

    Wednesday, July 5, 2006 11:32 PM

Answers

  • You may want to check if it is the same problem as described at the bottom of this thread. This exception may happen if you modify DataSet rows without respect for the nesting relationships ADO.NET originally inferred for them. For example, if you insert a new row, you have to set properly all hidden ID columns in order to preserve referential integrity. To pinpoint the offending operation, you may call WriteXml at intermediate points in your program. The code between the last successful WriteXml call and the first unsuccessful WriteXml is the offender.

    Hope it helps,
    Anton

    Thursday, July 6, 2006 12:14 AM
  • -Anton Lapounov, you are the man, this is what my problem was.

     

    When creating a table in Access and then exporting it as an xml file, when exporting, check schema of the data (xsd), click on more options - schema and change the default export location to embed shema in exported xml file.  Then when reading the xml file you readxml(xmlFile, readmode.ReadShema, and when writing the XML you WriteXML(strXMLFile, WriteMode.WriteSchema).

    Remember to add ASP .NET as a user with modify permissions for the XML file or it won't work.

     

    Thanks -Anton Lapounov
     Eric cann


    Monday, July 10, 2006 6:22 AM

All replies

  • You may want to check if it is the same problem as described at the bottom of this thread. This exception may happen if you modify DataSet rows without respect for the nesting relationships ADO.NET originally inferred for them. For example, if you insert a new row, you have to set properly all hidden ID columns in order to preserve referential integrity. To pinpoint the offending operation, you may call WriteXml at intermediate points in your program. The code between the last successful WriteXml call and the first unsuccessful WriteXml is the offender.

    Hope it helps,
    Anton

    Thursday, July 6, 2006 12:14 AM
  • I did incremental writexml statements and discovered that the offending code if just after I add a row to the dataset before writing it here is the source code:

     

    Dim dsGuestBook As New DataSet

    Dim strXMLFile As String = Server.MapPath(".") & "\gbcomments.xml"

    Try

    dsGuestBook.ReadXml(strXMLFile, XmlReadMode.InferSchema)

    Dim rowComment As DataRow = dsGuestBook.Tables("gbcomments").NewRow

    dsGuestBook.WriteXml(strXMLFile)

    rowComment("ID") = dsGuestBook.Tables("gbcomments").Rows.Count

    rowComment("gbname") = txtName.Text

    dsGuestBook.WriteXml(strXMLFile)

    If cboCountry.SelectedIndex > 0 Then rowComment("Country") = cboCountry.SelectedValue

    rowComment("gbemail") = txtEmail.Text

    dsGuestBook.WriteXml(strXMLFile)

    rowComment("gbdate") = DateTime.Now

    dsGuestBook.WriteXml(strXMLFile)

    rowComment("gbcomments") = txtComments.Text

    dsGuestBook.WriteXml(strXMLFile)

    dsGuestBook.Tables("gbcomments").Rows.Add(rowComment)      'This is where the problem lies

    dsGuestBook.WriteXml(strXMLFile)

    Catch ex As Exception

    lblStatus.Text = ex.Message

    End Try

     

    The table I'm writing to has fields (ID, gbname, gbcountry, gbemail, gbemail, gbdate, gbcomments

    The ID is an autonumber, i've tried not ommitting it and entering it and both methods don't work, please help!

    Friday, July 7, 2006 6:15 AM
  • Could you please post what the last successful dsGuestBook.WriteXml(strXMLFile) outputs? If the output is big, leave just a couple of rows, and make sure there is no sensitive information like SSN and CC numbers.

    Thanks,
    Anton

    Friday, July 7, 2006 7:46 AM
  • -Anton Lapounov, you are the man, this is what my problem was.

     

    When creating a table in Access and then exporting it as an xml file, when exporting, check schema of the data (xsd), click on more options - schema and change the default export location to embed shema in exported xml file.  Then when reading the xml file you readxml(xmlFile, readmode.ReadShema, and when writing the XML you WriteXML(strXMLFile, WriteMode.WriteSchema).

    Remember to add ASP .NET as a user with modify permissions for the XML file or it won't work.

     

    Thanks -Anton Lapounov
     Eric cann


    Monday, July 10, 2006 6:22 AM