Solved

Creating Primary-Foreign Keys when importing XML into MS Access

Posted on 2014-02-03
2
1,225 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 250 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 84

Assisted Solution

by:Scott McDaniel (Microsoft Access MVP - EE MVE )
Scott McDaniel (Microsoft Access MVP - EE MVE ) earned 250 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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Flowing down data to other tables 13 35
Access Change color of current datasheet row. 1 28
Copying an open file 3 22
Formatting Excel from Access with VBA... 5 21
Browsing the questions asked to the Experts of this forum, you will be amazed to see how many times people are headaching about monster regular expressions (regex) to select that specific part of some HTML or XML file they want to extract. The examp…
It’s been over a month into 2017, and there is already a sophisticated Gmail phishing email making it rounds. New techniques and tactics, have given hackers a way to authentically impersonate your contacts.How it Works The attack works by targeti…
Familiarize people with the process of utilizing SQL Server stored procedures from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Micr…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

830 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