Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: Multi-part unique key including parent key and child key

From: BlueMonkMN@-----.---
To: 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.



transparent
Print
Mail
Like It
Disclaimer
.

These Archives are provided for informational purposes only and have been generated directly from the Altova mailing list archive system and are comprised of the lists set forth on www.altova.com/list/index.html. Therefore, Altova does not warrant or guarantee the accuracy, reliability, completeness, usefulness, non-infringement of intellectual property rights, or quality of any content on the Altova Mailing List Archive(s), regardless of who originates that content. You expressly understand and agree that you bear all risks associated with using or relying on that content. Altova will not be liable or responsible in any way for any content posted including, but not limited to, any errors or omissions in content, or for any losses or damage of any kind incurred as a result of the use of or reliance on any content. This disclaimer and limitation on liability is in addition to the disclaimers and limitations contained in the Website Terms of Use and elsewhere on the site.

.
.

transparent

transparent