samsmithnz Posted May 20, 2004 Posted May 20, 2004 I have a dataset that is created from an XML document. This document usually looks something like this (except I have grossly simplified it): <Line> <RandomData></RandomData> <Items> <Item> <Code></Code> <Value></Value> </Item> <Item> <Code></Code> <Value></Value> </Item> </Items> </Line> I take this xml document and load it into a Dataset. This creates 3 tables, Line, Items and Item, along with several relations and constraints. I directly load the Item node into a datagrid to display my data. This is fine, but some XML responses I receive look like this: <Line> <RandomData></RandomData> <Items/> </Line> This isn't good, as it means I don't have the Item schema information anymore and can't add new items... or bind anything to my datagrid as the table doesn't even exits. So I've been trying to build the schema myself. Its easy adding the tables, but I CAN'T add the relations. The main thing here, is that there aren't any obvious foriegn and primary key columns to set with... can anyone help??? Quote Thanks Sam http://www.samsmith.co.nz
*Experts* Nerseus Posted May 20, 2004 *Experts* Posted May 20, 2004 If it were me, I'd load the DataSet with the full schema (using your first XML snippet that contains everything - or as much as you can get into one XML file). Save the DataSet using WriteXml with a second param of XmlWriteMode.WriteSchema. You can then create your dataset from the saved schema. When you want to load XML into the DataSet, use ReadXml and specify XmlReadMode.IgnoreSchema. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
samsmithnz Posted May 21, 2004 Author Posted May 21, 2004 Yeh that's what I had to do in the end. Its still weird how the relations are created on a XML document though, and weirder still that you can't replicate the relations programmatically. Quote Thanks Sam http://www.samsmith.co.nz
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.