Home. 
.

transparent

transparent

transparent

Altova Mailing List Archives


Re: XML. Create relationships.

From: "Neil Smith [MVP Digital Media]" <neil@------.--->
To: NULL
Date: 7/15/2009 1:19:00 PM
On Mon, 13 Jul 2009 05:49:11 -0700 (PDT), shapper <mdmoura@g...>
wrote:

>Hello,
>
>I am using XML files to save data for Products and Brands and I have
>the following (example):
>
><Products>
>  <Product>
>    <Id>1</Id>
>    <Name>Series 3</Name>
>    <Brand>
>      <Id>1</Id>
>      <Name>BMW</Name>
>    </Brand>
>  </Product>
></Products>
>
>And on Brands I have:
>
><Brands>
>  <Brand>
>    <BrandId>1</BrandId>
>    <Name>BMW</Name>
>  </Brand>
></Brands>
>
>I think that on products I should change it to:
>
>  <Product>
>    <ProductId>1</ProductId>
>    <Name>Series 3</Name>
>    <BrandId>1</BrandId>
>  </Product>


That would make sense - you can use XSD schema to enforce referential
integrity (a brand ID must exist for a corresponding product ID) if
for example you have data which is imported from other sources.


>Replicating how a database works and then using LINQ to build the
>Product object that contains Brand object.
>This way if a Brand changes I don't need to change all the records in
>Products.


Exactly.


>What do you think?
>
>And if I have a Many to Many relationship I could do something like:
>
><Products>
>  <Product>
>    <ProductId>1</ProductId>
>    <Name>Series 3</Name>
>  </Product>
></Products>
>
><Brands>
>  <Brand>
>    <BrandId>1</BrandId>
>    <Name>BMW</Name>
>  </Brand>
></Brands>
>
><ProductsBrands>
>  <ProductBrand>
>     <ProductId>1</ProductId>
>     <BrandId>1</BrandId>
>  </ProductBrand>
><ProductsBrands>
>
>Is this the way to go?


Personally, I would consider a Product can have multiple BrandId nodes
where you enumerate the exact relationship there - normalisation isn't
a feature of XML as it is for databases, and would result in redundant
data in your example.

Then your XPath becomes simpler, as you can match on any 

"/Products/Product/BrandId = 1"

instead of having something very awkward to read like 

"/ProductsBrands/ProductBrand/BrandId = 1 and
/ProductsBrands/ProductBrand/ProductId  = /Products/Product/BrandId"

I expect the first Xpath would be quick to process and the second
would have to do the (DB equivalent) of an index lookup, and possibly
result in duplicates. K.I.S.S should apply here ;-)

HTH
Cheers - Neil
------------------------------------------------
Digital Media MVP : 2004-2009
http://mvp.support.microsoft.com/mvpfaqs


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