Altova Mailing List Archives>Archive Index >microsoft.public.xml Archive Home >Recent entries >Thread Prev - XML. Create relationships. [Thread Next] Re: XML. Create relationships.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 | ||||||
| Company | Legal | Press | Partners | Careers | Sitemap | Contact Us | Altova Blog | Mobile | Full Site | |||
|
