Converting Excel to XML: A mapped element's relationship with other elements cannot be preserved

A client of mine provided me an excel spreadsheet of a list of wines to be placed on a website. I decided the best way to do so was to export the list into an xml file, then use it as a datasource for a .net gridview. The concept seemed simple enough.

However, when trying to convert from excel to xml, I received the following error message: "A mapped element's relationship with other elements cannot be preserved". So I did was most developers do, which is to check the xsd file for issues, researched the web for solutions, etc. But I found nothing that resolved my issue.

To make a long story short, what I found was that, although the list of wines contained 490 rows, excel was only detecting a subset of rows for certain columns. So for example, excel correctly identified 490 rows for each of my first 3 columns, but for whatever reason, even though the remaining 3 columns contained 490 rows of data, the xml mapping was only detecting 5 rows. So excel was complaining because the mapping (for whatever reason) could not see all 490 rows for all 6 columns.

To make this long story even shorter, I didn't know how my client created (and/or messed up) the spreadsheet, nor did I care. What I decided to do was to save the entire workbook into a new comma-delimited text file (csv file). I then opened the newly saved csv file in excel, and was able to successfully map and export the data into xml.

2 comments:

  1. Took forever but I finally ran across this. Thanks!

    ReplyDelete
  2. FYI, I quoted your answer here: http://stackoverflow.com/a/37736348/88257

    ReplyDelete