简体   繁体   中英

Export Mysql table into xml file same format as mysqldump using Perl

Using Perl how to export Mysql table into xml file the same format as mysqldump do with command like this:

mysqldump --xml -u root -proot dbname tablename >tablename.xml

I know some Perl modules like XML::TreePP easy to use but their problem when they load xml file they have to load the entire file into memory before parsing and if the file size is larger than the allowed process memory will crash.

If you need to parse very large XML documents, there's a particular category of XML parsers, SAX(Simple API for XML) that functions as a stream parser and emits events while parsing the XML document. On CPAN you can find XML::LibXML::SAX (part of the XML::LibXML module on CPAN) which implements SAX and can be used to parse large XML documents :

Such an interface is useful if very large XML documents have to be 
processed and no DOM functions are required. By using this interface
it is possible to read data stored within an XML document directly
into the application data structures without loading the document
into memory.

You can read another SO thread about a similar problem where XML::Twig was recommended.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM