Solved

Creating Primary-Foreign Keys when importing XML into MS Access

Posted on 2014-02-03
2
1,246 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to get data into a database 12 56
Combo box with two columns question 7 40
Batch convert csv to xlsx 10 60
View SQL Count Records 3 32
As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
In Part II of this series, I will discuss how to identify all open instances of Excel and enumerate the workbooks, spreadsheets, and named ranges within each of those instances.
Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…

739 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