Solved

Creating Primary-Foreign Keys when importing XML into MS Access

Posted on 2014-02-03
2
1,275 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 85

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
AutoNumbers should increment automatically, without duplicates.  But sometimes something goes wrong, and the next AutoNumber value is a duplicate.  This article shows how to recover from this problem.
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
Suggested Courses

628 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