trees and (typed) data sets db<-> xml

A

Andreas Leitner

Hi,

I would like to create an xml file based on data from a db
The xml file will then be edited by the user.
The modified xml file should then be remerged with the db.

Given I have the following table structure
(which models simple parent/child relation):

Parent:
ParentId (PK)
Name (vchar, not null, unique)

Child:
ChildId (PK)
ParentId (FK, not null)
Name (vchar, not null)

Additional restriction: 'Child.Name' must be unique within all children
of a given parent.

Now I can already export an XML file that looks like this:
--- listing 1
<ParentList>
<Parent ParentId="1">
<Name>P1</Name>
<Child ChildId="1">
<Name>P1.C1</Name>
</Child>
<Child ChildId="2">
<Name>P1.C2</Name>
</Child>
</Parent>
<Parent ParentId="2">
<Name>P1</Name>
<Child ChildId="3">
<Name>P2.C1</Name>
</Child>
</Parent>
</ParentList>
---

I define the relations and keys in the dataset schema,
and basically all work is done behind the scenes.
I just need to 'Fill's.

But really, what a user wants to see is:
--- listing 2
<ParentList>
<Parent>
<Name>P1</Name>
<Child>
<Name>P1.C1</Name>
</Child>
<Child>
<Name>P1.C2</Name>
</Child>
</Parent>
<Parent>
<Name>P1</Name>
<Child>
<Name>P2.C1</Name>
</Child>
</Parent>
</ParentList>
---
(i.e. All attributes stripped)
He is not interested at all in the 'id's of the elements.
This is also theoretically not a problem, since the names are all
unique. It is always possible to determine from the 'Name' (and the
parent) the corresponding row in the RDBMS.

But If I stip all the 'id's out of the schema, I strip also the basis
for my relations and keys that make the nesting of elements possible
(and I do want my elements to nest!)

What I could do is:
*) Leave the 'id's in the schema, retrieve dataset from db (i get equiv
of 'listing 1')
*) After the 'dataSet.WriteXML', run a XSLT sheet that strips them out
(i get equiv of 'listing 2')
*) Let the user edit the XSLT processed file (i.e edit 'listing 2')
*) Reimport the modified file (much more work now, since I have to do
many things by hand, and not just run a couplde of 'adapter.Update's)

But my good ol' stomach tells me this is suboptimal. Does anybody else
see a better solution?

many thanks in advance,
Andreas
 
K

Kathleen Dollard

Andreas,

There are various suboptimal ways of handling this situation. Whether you
use XSLT, or manually export the dataset, you will have to do the export
yourself. Experiement with ReadXML as it may import your edited file though.
There is no easy way to do this.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top