-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathxml.php
62 lines (49 loc) · 1.6 KB
/
xml.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
namespace oaiprovider\xml;
use oaiprovider\Header;
use oaiprovider AS oai;
use oaiprovider\OAIException;
use oaiprovider\output;
class NS {
const DC = "http://purl.org/dc/elements/1.1/";
const OAI_DC = "http://www.openarchives.org/OAI/2.0/oai_dc/";
const ESE = "http://www.europeana.eu/schemas/ese/";
const XML = "http://www.w3.org/2000/xmlns/";
const XSI = "http://www.w3.org/2001/XMLSchema-instance";
}
function appendHeader($xmlnode, Header $header) {
$headernode = appendElement($xmlnode, '', 'header');
if ($header->deleted) {
$headernode->setAttribute("status", "deleted");
}
appendElement($headernode, '', 'identifier', $header->identifier);
appendElement($headernode, '', 'datestamp', output\datetime($header->datestamp));
foreach($header->setSpec as $spec) {
if (!empty($spec)) {
appendElement($headernode, '', 'setSpec', $spec);
}
}
}
function appendRecord($node, Header $header, $metadata_xml) {
$r = appendElement($node, '', 'record');
appendHeader($r, $header);
if ($metadata_xml) {
$md = appendElement($r, '', 'metadata');
$metadata = new \DOMDocument();
$metadata->loadXML($metadata_xml);
$imported = $node->ownerDocument->importNode($metadata->firstChild, true);
$md->appendChild($imported);
}
}
function appendElement($node, $ns, $tagName, $value=null) {
if (empty($ns)) {
$el = $node->ownerDocument->createElement($tagName);
} else {
$el = $node->ownerDocument->createElementNS($ns, $tagName);
}
if ($value !== null) {
$el->nodeValue = output\escape($value);
}
$node->appendChild($el);
return $el;
}