开发者

Storing / retrieving parts of an xml document with mysql, php, and simpleXML

开发者 https://www.devze.com 2023-02-10 17:05 出处:网络
I\'m taking an xml document down from a partner API and I\'d like to store the separate nodes into a mysql database so I can rebuild it with specific nodes.I absolutely do not want to parse out the co

I'm taking an xml document down from a partner API and I'd like to store the separate nodes into a mysql database so I can rebuild it with specific nodes. I absolutely do not want to parse out the complete document into the database as all I care about are the IDs and the individual nodes in total.

So for example:

<list>
<child>20-30 grandchildren</child>
<child></child>
<child></child>
...
<child></child>
</list>

I'd like to be able to put the blocks into a mysql database and then restore them. That's where I'm falling down: I use simple_xml to get the node and I use REPLACE to add it as a text, but I'm not sure how to them restore it back to . For an array, I'd serialize and than unserialize but that fails here.

开发者_如何学运维

Is there an obvious method I'm missing?


You serialize SimpleXMLElement objects to XML with asXML() then you can load the document normally with simplexml_load_string()

You cannot serialize SimpleXMLElement with serialize(), it will not work as expected.

0

精彩评论

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