Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Convert Codex XML to Apple Dictionary XML
<?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