生成的xml未在浏览器中打开

时间:2016-02-16 14:20:21

标签: php xml dom

我编写了php代码来创建一个xml但是xml文件没有在浏览器中打开 以下是代码:

$dom = new DOMDocument('1.0','UTF-8');
$dom->formatOutput = true;

$root = $dom->createElement('journal');
$dom->appendChild($root);

$journal_metadata = $dom->createElement('journal_metadata');
$dom->appendChild($journal_metadata);

$journal_metadata->appendChild($dom->createElement('full_title', 'Economics'));
$journal_metadata->appendChild($dom->createElement('abbrev_title', 'JJD'));
$issn = $dom->createElement('issn','2142');
$journal_metadata->appendChild($issn);
$issn->setAttribute('media_type', 'electronic');

$journal_metadata->appendChild($dom->createElement('doi_data', 'JJD'));

$doi_data = $dom->createElement('doi_data');
$journal_metadata->appendChild($doi_data);

$doi = $dom->createElement('doi', '10.E');
$doi_data->appendChild($doi);

$resource = $dom->createElement('resource', 'http://localhost/fo/journal.php?jid=1');
$doi_data->appendChild($resource);

// journal issue
$journal_issue = $dom->createElement('journal_issue');
$dom->appendChild($journal_issue);

// journal article
$journal_article = $dom->createElement('journal_article');
$dom->appendChild($journal_article);
$journal_article->setAttribute('publication_type', 'full_text');

$pages = $dom->createElement('pages');
$journal_article->appendChild($pages);

 $resource = $dom->createElement('resource', htmlspecialchars('http://localhost/fo/abstracts.php?artID=472&jid=1'));
$doi_data->appendChild($resource);

echo '<xmp>'. $dom->saveXML() .'</xmp>';
$dom->save('result.xml') or die('XML Create Error');

0 个答案:

没有答案