Solved

Creating Primary-Foreign Keys when importing XML into MS Access

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The first two articles in this short series — Using a Criteria Form to Filter Records (http://www.experts-exchange.com/A_6069.html) and Building a Custom Filter (http://www.experts-exchange.com/A_6070.html) — discuss in some detail how a form can be…
When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
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.
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…

708 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now