0

How would I parse a very large xml file and insert it into a mysql database? I know PHP and I know javascript

1

3 Answers 3

4

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

Sign up to request clarification or add additional context in comments.

Comments

1

Another way (for MySQL 5.5) is a LOAD XML statement.

Comments

0

You would use an XML parser such as SimpleXML.

$xml = simplexml_load_string($yourXml);

// Do what you need to do...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.