How do I parse xml to insert it into a mysql database?
How would I parse a very large xm开发者_开发技巧l file and insert it into a mysql database? I know PHP and I know javascript
If it's a very large XML file you might not want to use DOM / SimpleXML as these load the complete XML tree into memory before allowing you to do any manipulation. If you are only interested in read operations you might want to look at XMLReader http://www.php.net/manual/en/class.xmlreader.php
XMLReader works by reading node by node, thus keeping speed up and memory usage down. There are a few interesting examples in the PHP documentation.
You can also look at SAX, an event based parser: http://php.net/xml_parser_create
Another way (for MySQL 5.5) is a LOAD XML statement.
You would use an XML parser such as SimpleXML.
$xml = simplexml_load_string($yourXml);
// Do what you need to do...
精彩评论