Moderators: jmacgreg, michael, jheckman, barbarah, btbell, bdgregg, asmecher
<?php
// Escape a string that will be used in XML.
function fix($string) {
return htmlspecialchars($string, ENT_NOQUOTES);
}
// Load article data for the export
function loadArticles ($filename) {
// Add code here to load the input file into a structure that looks like:
$data = array(
array(
'title' => 'First Article Title',
'abstract' => 'First Article Abstract',
'authors' => array(
'firstName' => 'Joe',
'lastName' => 'Public'
)
),
array(
'title' => 'Second Article Title',
'abstract' => 'Second Article Abstract',
'authors' => array(
'firstName' => 'Jane',
'lastName' => 'Doe'
)
)
);
return $data;
}
$articles = loadArticles('input.csv');
$issueTitle = 'Issue Title';
$volume = 1;
$number = 1;
$year = 1;
$out = fopen('output.xml', 'w');
if (!$out) die ('Cannot open output file.');
fwrite($out, "<?xml version=\"1.0\" ?>\n");
fwrite($out, "<issue published=\"true\">\n");
fwrite($out, "\t<title>" . fix($issueTitle) . "</title>\n");
fwrite($out, "\t<volume>" . $volume . "</volume>\n");
fwrite($out, "\t<number>" . $number . "</number>\n");
fwrite($out, "\t<year>" . $year . "</year>\n");
// For this sample script, put all articles in the same section
fwrite($out, "\t<section>\n");
fwrite($out, "\t<section>\n");
fwrite ($out, "\t\t<title>Articles</title>\n");
foreach ($articles as $article) {
fwrite ($out, "\t\t<article>\n");
fwrite ($out, "\t\t\t<title>" . fix($article['title']) . "</title>\n");
fwrite ($out, "\t\t\t<abstract>" . fix($article['abstract']) . "</abstract>\n");
foreach ($article['authors'] as $author) {
// ...etc...
}
// ...etc...
fwrite ($out, "\t\t</article>\n");
}
fwrite($out, "\t</section>\n");
fwrite($out, "</issue>\n");
fclose($out);
?>Users browsing this forum: mbria and 1 guest