Re: Saving dataset as nested XML

From: Richard L Rosenheim (richard_at_rlr.com)
Date: 10/10/04


Date: Sun, 10 Oct 2004 13:15:26 -0700

Thank for the tip about XMLSpy, I'll look into it.

Richard Rosenheim

"Paul Eden" <a@b.com> wrote in message
news:RVdad.575$Ii.166@newsfe6-gui.ntli.net...
> Richard
>
> Glad my ramblings were useful - many people on these groups have saved
> my backside before now (mainly in Compact Framework) - glad to finally
> be able to return the favour!
>
> In my schema, my child is nested but I only received the duplicate
> column error before I put on the service pack.
>
> Just for reference, I only use XMLSpy (free version) as I had untold
> issues with the inbuilt VS XML/XSD editors.
>
>
> Best regards
>
>
> Paul
>
>
>
> Richard L Rosenheim wrote:
> > Paul,
> >
> > Per your input, I installed Framework 1.1 SP1 on the machine, and
finally
> > was able to get the resulting XML file with the data nested.
> >
> > In the XSD Editor, I originally had the child table nested. In order
for
> > the code you provided to work, I had to un-nest the child table.
Otherwise,
> > I got a runtime error about duplicate field names. Once I un-nested the
> > table, your code worked, and the resulting XML file had the data nested.
> >
> > I also saved the schema with the data by specifying
> > "XMLWriteMode.WriteSchema" as part of the WriteXML method. Then, I took
the
> > resulting schema from the file, and pasted it back into the XSD Editor.
> > When I had the XSD Editor display the graphical view of the dataset, it
had
> > the table both nested, and a relationship defined. At this point, I was
> > able to delete the code you provided for defining the relations as the
> > dataset definition had the relationship properly defined.
> >
> > I think I always tried one approach (nested or relations) or the other.
At
> > least, I don't recall doing both at the same time. Of course, based
upon
> > your input, installing most likely SP1 help too.
> >
> > But in summary, for you or anyone else trying to define a schema in the
XSD
> > Editor with nested tables wanting the data to be nested too, you
apparently
> > have to both nest the tables, and define corresponding relationships.
> >
> > I do have one minor issue with the resulting XML data file. Because the
> > parent and the child tables both contains the parent ID field, that
field is
> > being included in the child's XML data. Which since the parent ID field
is
> > in the parent's data, is basically redundant information at the child's
> > level. At the moment, I'm not sure if it's possible to eliminate the
> > child's copy of the parent ID or how you would do it.
> >
> > Thanks again for you assistance -- your help really helped a lot,
> >
> > Richard Rosenheim
> >
> >
> >
> >
> > "Paul Eden" <a@b.com> wrote in message
> > news:cqf9d.491$_b2.434@newsfe6-gui.ntli.net...
> >
> >>Final installment (hopefully..)
> >>
> >>Found the issue with the nesting on my work PC - for some reason
> >>Windows Update had neglected to down load the Framework 1.1 SP1 (though
> >>I thought it was on). One download later all is well - hope you get the
> >>same results.
> >>
> >>
> >>Paul
> >>
> >>Richard L Rosenheim wrote:
> >>
> >>
> >>>Those issues are just a load of fun to track down.
> >>>
> >>>I've been tied up with an unexpected project (which they wanted ASAP,
of
> >>>course) and I haven't had a chance to give it a try. Hopefully over
the
> >>>weekend I'll be able to get to it.
> >>>
> >>>Richard Rosenheim
> >>>
> >>>
> >>>"Paul [Paradise Solutions]" <Paul@Don'tChuffingSpamMe.com> wrote in
> >
> > message
> >
> >>>news:ck17q5$qrm$1$8302bc10@news.demon.co.uk...
> >>>
> >>>
> >>>>Same person, different posting location...
> >>>>
> >>>>I don't think this has gone away - worked great at home, but at work I
> >>>
> >>>get:
> >>>
> >>>
> >>>>An unhandled exception of type 'System.Data.DuplicateNameException'
> >>>>occurred in system.data.dll
> >>>>
> >>>>Additional information: A column named 'Barcodes' already belongs to
> >>>>this DataTable: cannot set a nested table name to the same name.
> >>>>
> >>>>Exactly the same code that worked at home fails here.
> >>>>
> >>>>Both systems running Framework 1.1 +sp, Vs.Net2003 Ent Dev retail
> >>>>
> >>>>Work = XP and 2K server (server was justa convienient test machine)
> >>>>Home = 2K Pro
> >>>>
> >>>>
> >>>>Did the relationship suggestion work for you?
> >>>>
> >>>>
> >>>>Paul
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>Paul Eden wrote:
> >>>>
> >>>>
> >>>>>Essentially, the schema creates 2 relations (in my case)
> >>>>>
> >>>>>Customers.Customer_ID --> Addresses.Customer_ID
> >>>>>
> >>>>>and
> >>>>>
> >>>>>Addresses.Addresses_ID --> Address.Addresses_ID
> >>>>>
> >>>>>The following code created my output as nested:
> >>>>>
> >>>>> With CustomerData
> >>>>>
> >>>>>.ReadXmlSchema(IO.Path.GetDirectoryName(Application.ExecutablePath) &
> >>>>>"\Customer.xsd")
> >>>>> .Relations.Clear()
> >>>>> .Relations.Add("CustomerToAddresses",
> >>>>>.Tables(0).Columns("CustomerID"), .Tables(1).Columns("CustomerID"))
> >>>>> .Relations(0).Nested = True
> >>>>>
> >>>>> .Relations.Add("AddressesToAddress",
> >>>>>.Tables(1).Columns("AddressesID"), .Tables(2).Columns("AddressesID"))
> >>>>> .Relations(1).Nested = True
> >>>>> End With
> >>>>>
> >>>>>
> >>>>>
> >>>>>
> >>>>>Where CustomerID and AddressesID are my new additional fields.
> >>>>>
> >>>>>I also tried re-creating the relationships using the original
> >
> > fieldnames
> >
> >>>>>(with the '_', which are hidden fields) but once again my output was
> >>>
> >>>wrong.
> >>>
> >>>
> >>>>>The code should paste driect into IDE without problems.
> >>>>>
> >>>>>
> >>>>>Paul
> >>>>>
> >>>>>Richard L Rosenheim wrote:
> >>>>>
> >>>>>
> >>>>>
> >>>>>>Can you please provide more details of how you got it to work?
> >>>>>>
> >>>>>>I too have confirmed that the relationships are being created by
> >>>
> >>>checking
> >>>
> >>>
> >>>>>>the Relations. My child tables, in additional to an unique
autonumber
> >>>
> >>>ID
> >>>
> >>>
> >>>>>>field, also contains an ID field containing the parent ID. All
these
> >>>>>>fields
> >>>>>>are defined as of type "long". And, IsNested is defined as true in
> >
> > the
> >
> >>>>>>relation tags in the resulting XML Schema.
> >>>>>>
> >>>>>>Richard Rosenheim
> >>>>>>
> >>>>>>
> >>>>>>"Paul Eden" <a@b.com> wrote in message
> >>>>>>news:Xzg8d.202$y%3.31@newsfe1-win.ntli.net...
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>Richard
> >>>>>>>
> >>>>>>>I been fidling with this for most of the day. My Schema, when
loaded
> >>>>>>>into the dataset, generates all the relevent relationships (this I
> >
> > did
> >
> >>>>>>>not realise, going on the lack of correct output), with nested set
to
> >>>>>>>true (via interogating the dataset).
> >>>>>>>I finally too the step of clearing the Relations collection on the
> >>>
> >>>data
> >>>
> >>>
> >>>>>>>set, and re-creating them manually (which was a bit of a bugger,
> >>>>>>>becausae I had to go through and add ID fields for the
> >>>
> >>>relationships)...
> >>>
> >>>
> >>>>>>>BUT.. my ouput is now nested.
> >>>>>>>
> >>>>>>>A long winded and painfull fix, but it's the only one I found -
hope
> >>>
> >>>an
> >>>
> >>>
> >>>>>>>MS bod is reading - would be interesting to hear thier side.
> >>>>>>>
> >>>>>>>
> >>>>>>>Paul
> >>>>>>>
> >>>>>>>Richard L Rosenheim wrote:
> >>>>>>>
> >>>>>>>
> >>>>>>>
> >>>>>>>>You are correct -- having IsNested="true" doesn't seems to make
any
> >>>>>>>>difference what-so-ever. In the XML file that I attached to my
> >>>>>>>>previous
> >>>>>>>>post, it contained IsNested="true" attributes for the keys.
> >>>>>>>>
> >>>>>>>>Richard Rosenheim
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>"Paul Eden" <a@b.com> wrote in message
> >>>>>>>>news:0Rb8d.56$hs3.38@newsfe5-win.ntli.net...
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>Richard
> >>>>>>>>>
> >>>>>>>>>I'm having much the same issue. In one post I read that you have
> >>>>>>>>>to set
> >>>>>>>>>up the relationships in the dataset and have the relationship
> >>>>>>>>>flaged as
> >>>>>>>>>Nested=True, but this did not create the desired output either..
> >>>>>>>>>actually, it made no difference whatsoever. It might make a
> >>>>>>>>>difference
> >>>>>>>>>for you?
> >>>>>>>>>
> >>>>>>>>>I can post my schema and code if required.
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>Paul
> >>>>>>>>>
> >>>>>>>>>Richard L Rosenheim wrote:
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>
> >>>>>>>>>>I've been trying to save a dataset to a XML file and have the
> >
> > child
> >
> >>>>>>
> >>>>>>data
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>>>>nested under the parent data. Everything I have tried so far
> >>>
> >>>results
> >>>
> >>>
> >>>>>>in
> >>>>>>
> >>>>>>
> >>>>>>
> >>>>>>>>all
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>the records from the parent table being listed followed by all
the
> >>>>>>>>>>rows
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>of
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>the child table.
> >>>>>>>>>>
> >>>>>>>>>>As a result of previous posts, I currently created my tables
based
> >>>>>>>>>>upon
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>the
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>steps outlined in
> >>>>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingnestedrelationshipsinxmlschemas.asp
> >
> >>>>>>>>>>For my example, I created three tables: Contacts, Telephones and
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>Addresses
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>where Telephones and Addresses are defined as children of
> >>>>>>>>>>Contacts. In
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>the
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>resulting schema, Telephones and Addresses are nested within
> >>>>>>>>>>Contacts.
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>But
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>the actual data is not.
> >>>>>>>>>>
> >>>>>>>>>>What I'm looking to achieve is to have the data outputted in a
> >>>
> >>>format
> >>>
> >>>
> >>>>>>>>like:
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>> <Contacts>
> >>>>>>>>>> <Addresses>
> >>>>>>>>>> </Addresses>
> >>>>>>>>>> <Telephones>
> >>>>>>>>>> </Telephones>
> >>>>>>>>>> <Telephones>
> >>>>>>>>>> </Telephones>
> >>>>>>>>>> </Contacts>
> >>>>>>>>>>instead of the structure I'm getting:
> >>>>>>>>>> <Contacts>
> >>>>>>>>>> </Contacts>
> >>>>>>>>>> <Contacts>
> >>>>>>>>>> </Contacts>
> >>>>>>>>>> <Addresses>
> >>>>>>>>>> </Addresses>
> >>>>>>>>>> <Telephones>
> >>>>>>>>>> </Telephones>
> >>>>>>>>>> <Telephones>
> >>>>>>>>>> </Telephones>
> >>>>>>>>>>
> >>>>>>>>>>Anyone have any ideas? Attached is the resulting XML file I'm
> >>>>>>>>>>getting,
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>with
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>>>schema. I'm using Visual Studio 2003.
> >>>>>>>>>>
> >>>>>>>>>>TIA,
> >>>>>>>>>>
> >>>>>>>>>>Richard Rosenheim
> >>>>>>>>>>
> >>>>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>>>>>>
> >>>
> >
> >



Relevant Pages

  • Re: Saving dataset as nested XML
    ... In the XML file that I attached to my previous ... >> nested under the parent data. ... Telephones and Addresses are nested within Contacts. ... >> Richard Rosenheim ...
    (microsoft.public.dotnet.xml)
  • Re: Saving dataset as nested XML
    ... not realise, going on the lack of correct output), with nested set to ... > Richard Rosenheim ... it made no difference whatsoever. ... >>I can post my schema and code if required. ...
    (microsoft.public.dotnet.xml)
  • Re: Saving dataset as nested XML
    ... the schema creates 2 relations ... My child tables, in additional to an unique autonumber ID ... > Richard Rosenheim ...
    (microsoft.public.dotnet.xml)