Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Creating Primary-Foreign Keys when importing XML into MS Access

Posted on 2014-02-03
2
Medium Priority
?
1,331 Views
Last Modified: 2014-02-07
Hello,

I have an XML file given to me structured similarly to the one listed ( I can't post original XML).  I would like to import it into MS ACCESS.  It imports correctly into many tables but it doesn't add the Primary key of <RID> into the child tables as a foreign key.  In reading a few articles some say you have to parse things manually while others seem to suggest that creating a transform or schema may allow ACCESS to automatically provide the parent/child - Primary/Foreign Keys.  Can anyone point me in the right direction?  Custom Code or ?

 
<Record>
<RID>1</RID>
   <Person>
      <Name>John Does</Name>
      <Address>Main St</Address>
   </Person>
   <Person>
      <Name>Jane Doe</Name>
      <Address>Don't Walk</Address>
   </Person>
</Record>

<Record>
<RID>2</RID>
   <Person>
      <Name>Mike Smith</Name>
      <Address>Walk St</Address>
   </Person>
   <Person>
      <Name>Jane Doe</Name>
      <Address>Don't Walk</Address>
   </Person>
</Record>
0
Comment
Question by:zipnotic
2 Comments
 
LVL 4

Accepted Solution

by:
Jack Leach earned 1000 total points
ID: 39831931
Often times when importing data, I prefer to put it into a temp table first (or set of temp tables).  This allows me to "fix it up" and make sure everything's the way I want it, then you can INSERT INTO the final destination table, which would have the PK/FK columns and RI and such already defined.

Provided the temp table and final table column structures are the same, the INSERT statement is quite simple:

INSERT INTO ParentFinalTable SELECT * FROM ParentTempTable;
INSERT INTO ChildFinalTable SELECT * FROM ChildTempTable;
DELETE FROM ParentTempTable;
DELETE FROM ChildTempTable;
0
 
LVL 85

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 1000 total points
ID: 39832140
I've never really had good luck with the XML import feature of Access unless the incoming data was very simple. I ended up using the XMLDocument (part of the Microsoft XML library), which lets me open my incoming XML file and examine the structure, and then parse it as needed. There are many tutorials on use XML and such ...

Still, I use the temp table method suggested by Jack above. I parse my XML and insert to temporary tables, and then use standard VBA and SQL to move that to my live tables.
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Create a Windows 10 custom Image with custom task bar and custom start menu using XML for deployment.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
Add bar graphs to Access queries using Unicode block characters. Graphs appear on every record in the color you want. Give life to numbers. Hopes this gives you ideas on visualizing your data in new ways ~ Create a calculated field in a query: …
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

876 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question