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 7858023
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T21:14:01+00:00 2026-06-02T21:14:01+00:00

Where do I begin… a XML file needs to go into a database. Therefore

  • 0

Where do I begin… a XML file needs to go into a database. Therefore I want to make a config array containing the mapping between XML nodes and table-columns of one table.

$maps = array(
 // 'node-name'=>'column-name'
 'prod_id'=>'supplier_product_id',
 'description'=>'product_description',
);

$xml=simplexml_load_file($file);

//just a test
foreach ($maps as $node => $col){
 echo 'node ' . $xml->$node . ' is mapped to: ' . $col; //this works
}

There is information I need to put in this (same) table, from a subnode. So I was thinking of putting subnodes in a nested array like this:

$maps = array(
 // 'node-name'=>'column-name'
 'prod_id'=>'supplier_product_id',
 'description'=>'product_description',
 // to access $xml->node->subnode;
 'category'=>array(
  'id'=>'category_id',
 ),
);

But now I get confused, how can I use the nested array to make an path to the node like this:
$xml->category->id

I am a newbee in PHP and hopefully some help will keep me on the road again.
All help is welcome, thank you in advance.

  • 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-06-02T21:14:03+00:00Added an answer on June 2, 2026 at 9:14 pm

    Try this:

    <?php
    $maps = array(
     // 'node-name'=>'column-name'
     'prod_id'=>'supplier_product_id',
     'description'=>'product_description',
     // to access $xml->node->subnode;
     'category'=>array(
      'id'=>'category_id'
     )
    );
    
    function getDataMapping( $maps, $child="" ) {
        global $file;
    
        $xml=simplexml_load_file($file);
    
        foreach ($maps as $node => $col) {
            if( is_array( $col ) ) {
                getDataMapping( $col, $node );
            } else {
                if( $child ) {
                    echo 'node ' . $xml->{$child}->$node . ' is mapped to: ' . $col; //this works
                } else {
                    echo 'node ' . $xml->$node . ' is mapped to: ' . $col; //this works
                }
            }
        }
    }
    
    getDataMapping( $maps );
    ?>
    

    Obviously, if your nesting runs many levels deep (array within array and so on), you can change it to a recursive function.

    Hope this helps.

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

Sidebar

Related Questions

Before I begin I want to make it clear that I don't want the
To begin i read all resources from xml in my MergedDictionaries and now I
To begin with, I have a database that holds map data for a game
Cloud server begin generate big disk read/write operation. I want find some script who
begin #some routine rescue retry #on third retry, output no dice! end I want
Just to begin, I've read Read text file in a folder and other troubleshooting
I begin with java and I'm searching for how to create an array 2d
Begin Edit: Primarily I want my Clojure program to use a Java class. I've
begin # make a new outgoing call @call = @client.account.calls.create( :from => '+1*********', :to
So how to begin. I am asking when you make a game for example

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.