开发者

cakephp xml parser

I am parsing cakephp using xml parser. It parses it just fine. Its a huge xml开发者_JAVA百科. 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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜