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

  • Question

  • hi every one

    i got a error when i tried to write xml file from the dataset. All elements of xml are populated run time in the dataset except --dataset shows on new row 'SupportItems_Id' which is not exist in the xml file.

    this is the code-----
    if (strAlbumName != "" && strAlbumPath != "")
                {
                    strXMLFile = strAlbumPath + "\\" + strAlbumName + ".linkinfo.xml";
                    XmlDocument doc = new XmlDocument();
                    doc.Load(strXMLFile);
                    System.Data.DataSet objDataSet = new DataSet();
                    objDataSet.ReadXml(strXMLFile);
                    for (int i = 0; i < objDataSet.Tables.Count - 1; i++)
                    {
                        if (objDataSet.TablesIdea.TableName == "ScreenSupportItem")
                        {
                            for (int j = 0; j < objDataSet.TablesIdea.Rows.Count; j++)
                            {
                                if (Convert.ToInt32(objDataSet.TablesIdea.Rows[j]["RefId"]) == 3)
                                {
                                    string strFilePath = FileUpload.PostedFile.FileName;
                                    DataRow newrow = objDataSet.TablesIdea.NewRow();
                                    newrow["LinkDate"] = System.DateTime.Today;
                                    newrow["LinkAuthor"]= "SUBHASH\\Login Subhash";
                                    newrow["LinkURL"] = FileUpload.PostedFile.FileName;
                                    newrow["LinkText"] = txtUrlTitle.Text;
      newrow["OptionalSupportInstruction"] = "Nothing";
                                    newrow["RefId"] = 3;
                                    objDataSet.TablesIdea.Rows.Add(newrow);
                                    objDataSet.AcceptChanges();
                                    objDataSet.GetXml();
                                    break;
                                }
                            }
                        }
                    }
                    objDataSet.WriteXml(strXMLFile);
                }

    and these are the few lines of  xml file--

    <ScreenToSupport>
          <ScreenUniqueId>e7dfee93-14f0-4775-baef-c7246dfae902</ScreenUniqueId>
          <Label>label3</Label>
          <ScreenMatchProbabilityLevel>172.0934</ScreenMatchProbabilityLevel>
          <SupportItems>
            <ScreenSupportItem>
              <LinkDate>2007-10-25T11:47:10.515625+05:30</LinkDate>
              <LinkAuthor>SUBHASH\Login Subhash</LinkAuthor>
              <LinkURL>D:\Baydon\ls.html</LinkURL>
              <LinkText>Testing Help file</LinkText>
              <OptionalSupportInstruction />
              <RefId>3</RefId>
            </ScreenSupportItem>

    I am new in xml , any body please try to solve my problem
    Thanks in advance.

    Monday, November 5, 2007 11:23 AM

All replies

  • I think your problem isn't Xml related but comes from the way you use the DataSet. I copied your code and the input you provided (had to fix it up some) and then put a break point at this statement:

    Code Block
    objDataSet.GetXml();

     

     

    If you evaluate this in the QuickWatch window you'll see that it returns non-well formed Xml. If you examine the value in the text visualizer, you'll see that the Xml you get is

    Code Block

    <ScreenToSupport>

     ....

    </ScreenToSupport>

    <ScreenSupportItem>

    <LinkDate>TestNewData</LinkDate>

    </ScreenSupportItem>

     

     

    The last three lines corresond to the new row inserted (I dumbed it down some) -- in other words, the new row gets serialized as a sibling to the root element. This is exactly why the writer is giving the error you're seeing.

     

    I couldn't quickly figure out the proper way to add your data row -- maybe someone else here can help or you could try the folks on the Data Access forum:

    http://forums.microsoft.com/MSDN/ShowForum.aspx?ForumID=45&SiteID=1

    Thursday, December 27, 2007 4:52 AM