Ik heb een XML-bestand dat ik op een genormaliseerde manier in een database wil ontleden. Tabel twee is het idee dat ik had om een one-of-many relatietabel te maken. De naam, titel verandert nooit voor elke bestandsgroep, maar de downloadpaden zullen anders zijn.
tafel 1
id | name | title | download_path
----------------------------------------------------------------------
1 | FileGroup 1 | This is the first file group | /this/1/1.zip
2 | FileGroup 1 | This is the first file group | /this/1/2.zip
3 | FileGroup 2 | This is the second file group | /this/2/1.zip
4 | FileGroup 2 | This is the second file group | /this/2/2.zip
5 | FileGroup 3 | This is the third file group | /this/3/1.zip
XML-bestand
-
File Group 1
<title>This is the first file group</title>
/this/1/1.zip
-
File Group 1
<title>This is the first file group</title>
/this/1/2.zip
-
File Group 2
<title>This is the second file group</title>
/this/2/1.zip
-
File Group 2
<title>This is the second file group</title>
/this/2/2.zip
-
File Group 3
<title>This is the third file group</title>
/this/3/1.zip
tafel 2
group_id | file_id
-----------------------------
1 | 1
1 | 2
2 | 3
2 | 4
3 | 5
What is the best way to do this when parsing through the XML. If i put the xml data into an array and foreach through each item, i need to be able to able to group them on the fly and create the relationship in tafel 2. I did have the idea of just creating tafel 1 and then afterwards building the relationship table, but even then then i dont know how best to group them. I have nothing in the xml to say they are grouped other that name and title. Each group can have any number of file download paths.
I do not have any say on the XML-bestand creation. Its all I have to deal with.