Asim Zaidi
Asim Zaidi

Reputation: 28284

cakephp xml parser

I am parsing cakephp using xml parser. It parses it just fine. Its a huge xml. I now need to enter that into a database. Any easy way to do it without going into too much trouble with all those arrays and sub arrays

Thanks

Upvotes: 0

Views: 652

Answers (1)

Chuck Burgess
Chuck Burgess

Reputation: 11574

This all depends on what the array looks like and how you want to store the data. If you just need to capture the array, you can use serialize:

$data = serialize($xml_array)

And store that in a text field.

If you need to store each item in the array, you can do that easy enough as long as there are not sub-arrays within the array. If it is for example and array like this:

array(
  [MyArray] => (
     [Field1] => 'data',
     [field2] => 'data',
  )
)

and the Field1 and field2 match the columns of the table, just change [MyArray] to the model name and pass the array to the model->save() function and it will save the data.

However, if you have sub-array information:

array(
  [MyArray] => (
     [Field1] => array([sub_array] => 'more_data'),
     [field2] => 'data',
  )
)

Your only option is to parse the data into an array that can be saved and then save it.

Upvotes: 1

Related Questions