-
-
Save Mabahe/09e66e39bf26670a167282cfb4217db8 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// INPUT: phpMyAdmin xml-dump | |
// HOW TO: on CLI: php dump-to-dataset.php dumpfile.xml | |
// OUTPUT: dumpfile.xmldataset.xml | |
$xsl = "<xsl:stylesheet version='1.0' xmlns:xsl='http://www.w3.org/1999/XSL/Transform'> | |
<xsl:template match='/'> | |
<dataset><xsl:text>
</xsl:text> | |
<xsl:for-each select='pma_xml_export/database/table'> | |
<xsl:variable name='e' select='@name'/> | |
<xsl:element name='{\$e}'><xsl:text>
</xsl:text> | |
<xsl:for-each select='column'> | |
<xsl:if test='.!= \"NULL\"'> | |
<xsl:variable name='c' select='@name'/> | |
<xsl:element name='{\$c}'> | |
<xsl:value-of select='.' /> | |
</xsl:element><xsl:text>
</xsl:text> | |
</xsl:if> | |
</xsl:for-each> | |
</xsl:element><xsl:text>
</xsl:text> | |
<xsl:text>
</xsl:text> | |
</xsl:for-each> | |
</dataset> | |
</xsl:template> | |
</xsl:stylesheet> | |
"; | |
if(empty($argv[1])){ | |
exit("bitte name des Dumps angeben!\n"); | |
}else{ | |
$sourceFile = $argv[1]; | |
} | |
if(file_exists($sourceFile)){ | |
$xml = simplexml_load_file($sourceFile); | |
$import = loadFile($sourceFile, $xsl); | |
file_put_contents($sourceFile."dataset.xml", $import); | |
}else{ | |
exit("no '".$sourceFile."' found"); | |
} | |
function loadFile($xml, $xsl) | |
{ | |
$xmlDoc = new DOMDocument(); | |
$xmlDoc->load($xml); | |
$xslDoc = simplexml_load_string($xsl); | |
$proc = new XSLTProcessor(); | |
$proc->importStyleSheet($xslDoc); | |
return $proc->transformToXML($xmlDoc); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment