From: jon Date: November 1 2007 5:10pm Subject: svn commit - mysqldoc@docsrva: r8474 - trunk/ndbapi List-Archive: http://lists.mysql.com/commits/36905 Message-Id: <200711011710.lA1HAi3s018399@docsrva.mysql.com> Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: jstephens Date: 2007-11-01 18:10:44 +0100 (Thu, 01 Nov 2007) New Revision: 8474 Log: Debugged script (hopefully), added a --debug switch and some comments... Modified: trunk/ndbapi/fix-indexes Modified: trunk/ndbapi/fix-indexes =================================================================== --- trunk/ndbapi/fix-indexes 2007-11-01 15:32:22 UTC (rev 8473) +++ trunk/ndbapi/fix-indexes 2007-11-01 17:10:44 UTC (rev 8474) Changed blocks: 1, Lines Added: 71, Lines Deleted: 24; 2886 bytes @@ -1,44 +1,91 @@ #!/usr/bin/php elements contained + # within and elements found in those files + + # Purpose: Clean up sub-optimal indexing in DocBook XML files + + # Requires: PHP 5 with DOM and SimpleXML extensions + # (tested with PHP 5.2.0 on SuSE Linux 10.2) + + # Invoke with --debug for some debugging output + + $__DEBUG__ = $argc > 0 && $argv[1] == '--debug' ? TRUE : FALSE; + + function remove_tags($el) +{ + global $__DEBUG__; + + $tag = $el->tagName; + + if($__DEBUG__) + echo "Processing $tag element; "; + + $simple = simpleXML_import_DOM($el); + $xml = $simple->asXML(); + + if($__DEBUG__) + echo "original text in element: $xml;"; + + $text = preg_replace('/<\/?(literal|' . $tag . ')>/', '', $xml); + + if($__DEBUG__) + echo " text after processing: $text\n"; + + $owner = $el->ownerDocument; + + $text_node = $owner->createTextNode($text); + + $new_el = $owner->createElement($tag); + $new_el->appendChild($text_node); + + return $new_el; +} + + $files = scandir("."); - + + $files_processed = 0; + $tags_processed = 0; + foreach($files as $file) { if(is_file($file) && strpos($file, '.xml')) { + if($__DEBUG__) + echo "\nProcessing $file... "; + + $files_processed++; + $doc = DOMDocument::load($file); - + $primaries = $doc->getElementsByTagName('primary'); $secondaries = $doc->getElementsByTagName('secondary'); - + + $tags = count($primaries) + count($secondaries); + $tags_processed += $tags; + + if($__DEBUG__) + echo "$tags tags to be processed in this file...\n"; + $index_sets = array($primaries, $secondaries); - + foreach($index_sets as $indexes) foreach($indexes as $index) - $index->parentNode->replaceChild(remove_tags($index), $index); - + $index->parentNode->replaceChild(remove_tags($index), $index); + + $doc->save($file); + unset($doc); } } - - function remove_tags($el) - { - $tag = $el->tagName; - $simple = simpleXML_import_DOM($el); - $text = preg_replace('/<\/?(literal|' . $tag . ')>/', '', $simple->asXML()); - - echo "$text\n"; - - $owner = $el->ownerDocument; - - $text_node = $owner->createTextNode($text); - - $new_el = $owner->createElement($tag); - $new_el->appendChild($text_node); - - return $new_el; - } + echo "\nProcessed $tags_processed tags + in $files_processed XML files.\nDone.\n"; + ?> \ No newline at end of file