Last active
February 19, 2021 16:11
-
-
Save brasofilo/e39b5d88b52a649eb3bb to your computer and use it in GitHub Desktop.
Convert Codex XML to Apple Dictionary XML
This file contains 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 | |
header('Content-type: text/xml'); | |
header('Pragma: public'); | |
header('Cache-control: private'); | |
header('Expires: -1'); | |
echo "<?xml version=\"1.0\" encoding=\"utf-8\"?>\r\n"; | |
echo '<d:dictionary xmlns="http://www.w3.org/1999/xhtml" xmlns:d="http://www.apple.com/DTDs/DictionaryService-1.0.rng">' . "\r\n"; | |
$codex = simplexml_load_file('codex.xml'); | |
$count = 0; | |
foreach( $codex->page as $page ) | |
{ | |
$title = str_replace( 'Function Reference/', '', $page->title ); | |
$id = str_replace( ' ', '_', $title ); | |
# Avoid adding translated resources | |
if( false !== strpos( $title,':' ) ) | |
continue; | |
printf(' | |
<d:entry id="%1$s" d:title="%2$s"> | |
<d:index d:value="%2$s"/> | |
<h1>%2$s</h1> | |
<p>%3$s</p> | |
</d:entry>', | |
$id, | |
$title, | |
htmlentities( $page->revision->text ) | |
); | |
echo "\r\n"; | |
} | |
echo '</d:dictionary>'; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment