<table name> cannot be the child table in two nested relations RRS feed

  • Question


    I searched and found some posts that referred to this error, but did not refer to my specific problem and/or have a solution.


    I am programming in C#, taking a .xml file provided by a third party, reading it in, doing some processing, and then outputting it.


    I have gotten sample .xml's and used Xsd.exe to first create a .xsd then a C# class file.


    However, apparently the .xml data has some nested tables with the same name, and when instantiating my dataset during run-time I get the "<table name> cannot be the child table in two nested relations " error.


    NewDataSet set1 = new NewDataSet(); // Error here, before reading.


    A brief example of the .xml data I'm getting:













    So, I would be getting the error because of PayList.  Each Paylist, however, contains different values based upon whether the item is a Matrix item or a non-Matrix item.  I therefore need to retain both those elements.


    I cannot modify the incoming .xml, as I am not generating it ... so what is the best solution to handle this situation?  I am pretty new to .NET and DataSets, so I'm sure there is something I'm missing, but it seems strange that it doesn't recognize that the different PayLists have different parents, and therefore are separate items. 




    Tuesday, March 18, 2008 9:20 PM


  • This question probably would be better directed to the ADO.NET forum.  That said, here's the problem:


    When ADO reads XML into a DataSet, it creates DataTables to contain each type of element it encounters.  Each table is uniquely identified by its name.  You can't have two different tables named "PayList". 


    Also, a given table can have any number of parent tables, but only one of its parent relations can be nested - otherwise, a given record would get written to the XML multiple times, as a child of each of its parent rows.


    It's extremely convenient that the DataSet's ReadXml method can infer the schema of the DataSet as it reads its input, but the XML has to conform to certain constraints if it's going to be readable.  The XML you've got doesn't.  So you have two alternatives:  you can change the XML, or you can write your own method to populate the DataSet.


    If it were me, I'd write an XSLT transform that took the input XML and turned PayList elements into either MatrixPayList or NonMatrixPaylist elements.  Then I'd pass its output to the DataSet.


    Wednesday, March 19, 2008 8:06 PM