Yii Framework Forum: multidimensional arrays to form a path to XML subnodes - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

multidimensional arrays to form a path to XML subnodes Rate Topic: -----

#1 User is offline   ametad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 08-February 12
  • Location:Holland

Posted 26 April 2012 - 11:21 AM

Hello people,

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

0

#2 User is offline   ametad 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 78
  • Joined: 08-February 12
  • Location:Holland

Posted 26 April 2012 - 11:23 AM

All help is welcome, thank you in advance :)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users