Page 1 of 1

Schema to convert XML into relational database

Posted: Mon Jan 19, 2015 6:33 pm
by ma701ss

I have the following sample code:

Code: Select all

<?xml version="1.0" ?>
    <CATEGORY id='181' name='Category name'>
      <PRODUCT ITEM='7451'>
        <NAME>Product name</NAME>
        <MODEL>Product model</MODEL>
        <DESCRIPTION>Product description.</DESCRIPTION>
      <PRODUCT ITEM='7452'>
        <NAME>Product 2 name</NAME>
        <MODEL>Product 2 model</MODEL>
        <DESCRIPTION>Product 2 description.</DESCRIPTION>

I created a schema for this (reverse engineered) using an online editor. The trouble is the data in the XML file does not convert correctly into a relational database format. For example I need the category ID to be on each "product" row, and product item refers to the unique ID for each product but it's an attribute and it doesn't get recognised as such. There may be many products within the same category ID. I need to have the following columns in my table, and for the XML to be converted into such a format that I can import into SQL Server:

Product Item (Primary Key)
Category ID
Product Name

Is it a case of re-writing the XML schema to do this?