-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractCodeList.php
More file actions
66 lines (55 loc) · 1.83 KB
/
Copy pathextractCodeList.php
File metadata and controls
66 lines (55 loc) · 1.83 KB
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
62
63
64
65
66
<?php
/**
* Extract code list from http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml
* */
$url = "http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/codelist/gmxCodelists.xml";
$doc = new DOMDocument();
$doc->load($url);
$nodes = $doc->getElementsByTagName("CodeListDictionary");
function extractValues($node) {
$definition = $node->getElementsByTagName("CodeDefinition")->item(0);
//foreach ($definitions as $definition) {
$identifier = $definition->getElementsByTagNameNS("*","identifier")->item(0);
$description = $definition->getElementsByTagNameNS("*","description")->item(0);
// var_dump(array($identifier->nodeValue, $description->nodeValue));
return array($identifier->nodeValue, $description->nodeValue);
// var_dump($tab);
}
$values = array();
foreach ($nodes as $codelist) {
$childs = $codelist->childNodes;
$list = array();
foreach($childs as $child) {
switch($child->nodeName) {
case 'gml:identifier':
$name = $child->nodeValue;
break;
case 'codeEntry':
$list [] = extractValues($child);
break;
}
}
$values[$name] = $list;
$fp = fopen('codeList/'.$name.'.csv', 'w');
fputcsv($fp, array("identifier", "description_en"));
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
chmod('codeList/'.$name.'.csv', 0777);
}
var_dump($values);
// function XML2Array(SimpleXMLElement $parent)
// {
// $array = array();
// foreach ($parent as $name => $element) {
// ($node = & $array[$name])
// && (1 === count($node) ? $node = array($node) : 1)
// && $node = & $node[];
// $node = $element->count() ? XML2Array($element) : trim($element);
// }
// return $array;
// }
// $xml = simplexml_load_file($url);
// $array = XML2Array($xml);
// var_dump($array['codelistItem']);