Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6735063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:57:49+00:00 2026-05-26T10:57:49+00:00

I have an XML file that I want to parse into a database in

  • 0

I have an XML file that I want to parse into a database in a normalized fashion. Table two is the idea I had for creating a one to many relationship table. The name,title will never change for each file group, but the download paths will be different.

Table 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 File

<Item>
    <Name>File Group 1</Name>
    <Title>This is the first file group</Title>
    <DownloadPath>/this/1/1.zip</DownloadPath>
</Item>
<Item>
    <Name>File Group 1</Name>
    <Title>This is the first file group</Title>
    <DownloadPath>/this/1/2.zip</DownloadPath>
</Item>
<Item>
    <Name>File Group 2</Name>
    <Title>This is the second file group</Title>
    <DownloadPath>/this/2/1.zip</DownloadPath>
</Item>
<Item>
    <Name>File Group 2</Name>
    <Title>This is the second file group</Title>
    <DownloadPath>/this/2/2.zip</DownloadPath>
</Item>
<Item>
    <Name>File Group 3</Name>
    <Title>This is the third file group</Title>
    <DownloadPath>/this/3/1.zip</DownloadPath>
</Item>

Table 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 table 2. I did have the idea of just creating table 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 file creation. Its all I have to deal with.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T10:57:50+00:00Added an answer on May 26, 2026 at 10:57 am

    Your table structure is not normalized. You can update one FileGroup/Title row without updating the other, and this would be wrong. Instead, FileGroup/Title should be in one table and FileGroup/download_path should be in another table.

    As for organizing the DB based on the xml, imagine you are parsing the xml by node:

    $groups = array();
    foreach ($Items as $Item) {
       if (!isset($groups[$Item->Name])) {
          $groups[$Item->Name] = array(
             'title' => $Item->Title
             , 'files' => array();
          );
       }
       $groups[$Item->Name]['files'][] = $Item->DownloadPath;
    }
    

    The xml in your example is also invalid, so good luck processing it if that’s how it really is..

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an xml file that I want to configure using a bash script.
I have a flash applet that I want to grab a remote XML file
I have a ListView that is populated using an XML file. However, I want
I have an XML file that I'm trying to serialize into an object. Some
I have a file that keeps appending the following xml. What I want to
I'm trying to parse a massive xml file into my MySQL database. the file
I have this XML file which I parse into an ArrayList In this ArrayList
I have a MySQL database/table set up and a .php file online that inserts
I have an XML file that starts like this: <Elements name=Entities xmlns=XS-GenerationToolElements> I'll have
I have an XML file that encodes a directed acyclic graph (DAG) that represents

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.