Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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???

  • *Experts*
Posted

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

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...