Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - Multi-part unique key including parent key and child key [Thread Next] Re: Multi-part unique key including parent key and child keyTo: NULL Date: 10/2/2005 7:57:00 AM After many hours of tedious experimentation I have found the solution I'm looking for and will post it in case it can save someone else some time. Originally I had my schema set up without nested relationships, which resulted in a messy-looking XML output file when I wrote the data to a file (it was all flat and every child table had to explicitly specify all its parents' key values). So my goal was to get these elements nested and not to duplicate the parent key values in all the child elements. It turns out you can do that by setting the nested property of the relationship to true. It also occurs of you embed the elements in the parent element in the schema, but the problem I encountered there was that I could no longer specify primary key contraints that way because the columns referring to the parent table were implicit and the XSD designer did not allow me to access them. But having embedded elements does not preclude me from adding "duplicate" relationships and columns in the child elements. And I've found that if I set the "use" property of the key attributes on the child elements to "prohibited" then they don't come out in the XML. So I think this could be done without embedding elements (just define nested relationships) but I have them embedded and it seems to work OK. So in the end what I've ended up with is all top level classes have a "Name" attribute which is their primary key. I have embedded child elements into these by creating each child element and dragging it onto its parent, which adds an attribute to the parent. Then in order to be able to set up constraints properly, I added a column to the child element called "Name" (matching the "Name" column from the parent element). I set the "use" property of this attribute to "prohibited" to prevent it from coming out in the XML. Then for a child element whose unique key is, for example, a combination of the parent Name and the child's "FrameValue" attribute, I can easily create this constraint because both columns are now explicit and visible on the child element. I also created a relationship between the parent element and the child element to match the Name attribute from the child with the Name attribute from the parent. It seems redundant, but the XSD designer seems intelligent enough to pick up on the fact that there's this other relationship it can use to embed one element in the other, and it won't duplicate relationships or constraints or keys (as far as I can tell). And now when I write out the XML, it looks perfect. The child element is embedded in the parent element without duplicating the parent element's key (Name) attributes. I don't see any unnecessary duplication or extraneous columns or keys in the output's schema or data. This also works well for more than one level of nesting. I have a grandchild element that includes key attributes from both the parent and grandparent, which are used to define the grandchild's primary key. | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
