I'm trying to import an XML file into Access but it creates 3 unrelated tables. That is, the child records are imported into the child table, but there is no way of knowing which child records belong to which parent.
How can I import the data to maintain the relationship between the parent and child nodes (records)?
Here is a sample of the XML data:
<NOTARIO>
<C_NOT>8404180</C_NOT>
<APE>Abalos Nuevo</APE>
<NOM>Francisco José</NOM>
<NOTARIAS>
<NOTARIA>
<PRO>23</PRO>
<MUN>0888</MUN>
<F_IN>1984-12-01</F_IN>
<F_FI>1986-09-19</F_FI>
</NOTARIA>
<NOTARIA>
<PRO>14</PRO>
<MUN>0569</MUN>
<F_IN>1990-09-17</F_IN>
<F_FI>1995-03-15</F_FI>
</NOTARIA>
<NOTARIA>
<PRO>21</PRO>
<MUN>0412</MUN>
<F_IN>1995-03-30</F_IN>
<F_FI></F_FI>
</NOTARIA>
</NOTARIAS>
</NOTARIO>
What you need to do is transform your XML data into a format that works better with Access. Specifically, you need to insert the parent key value (assuming that it is
C_NOT
in this case) into each child node.The following XSLT file will do that for you
That will transform your XML from this ...
... into this:
... in the background while Access is importing it.
Save that XSLT file to your hard drive (I called mine "transformio.xslt"), then start the Access XML import process. Once you've selected your XML file to import, click the "Transform" button ...
... add your newly-created XSLT file to the list and select it ...
When you click "OK" and return to the "Import XML" dialog, you can expand the tree view to see that you now have
C_NOT
values in both tables.When the import is complete you will still have two tables, but now you can JOIN them on
C_NOT
to get a "flat" view of the data:which gives us