-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextractCodeListML.php
More file actions
76 lines (66 loc) · 2.52 KB
/
Copy pathextractCodeListML.php
File metadata and controls
76 lines (66 loc) · 2.52 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
67
68
69
70
71
72
73
74
75
76
<?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/ML_gmxCodelists.xml";
$url = "ML_gmxCodelists.xml";
$doc = new DOMDocument();
$doc->load($url);
// $xpath = new DOMXpath($doc);
// $ns = $doc->documentElement->namespaceURI;
// $xpath->registerNamespace("gml", $ns);
$nodes = $doc->getElementsByTagName("ML_CodeListDictionary");
function extractValues($node) {
global $xpath;
$definition = $node->getElementsByTagName("ML_CodeDefinition")->item(0);
//foreach ($definitions as $definition) {
$identifier = $definition->getElementsByTagNameNS("*","identifier")->item(0);
$description = $definition->getElementsByTagNameNS("*","description")->item(0);
$name = $definition->getElementsByTagNameNS("*", "name")->item(0);
$alternative = $definition->getElementsByTagName("CodeAlternativeExpression")->item(0);
$description_fr = $alternative->getElementsByTagNameNS("*","description")->item(0);
$name_fr = $alternative->getElementsByTagNameNS("*", "name")->item(0);
var_dump($name_fr);
// var_dump(array($identifier->nodeValue, $description->nodeValue));
return array($identifier->nodeValue, $name->nodeValue, $description->nodeValue, !is_null($name_fr)? $name_fr->nodeValue : "", !is_null($description_fr) ? $description_fr->nodeValue : "");
// var_dump($tab);
}
$values = array();
foreach ($nodes as $codelist) {
$list = array();
$childs = $codelist->childNodes;
foreach($childs as $child) {
switch($child->nodeName) {
case 'gml:identifier':
$name = $child->nodeValue;
break;
case 'codeEntry':
$list [] = extractValues($child);
break;
}
}
var_dump($list);
$values[$name] = $list;
$fp = fopen('codeListML/'.$name.'.csv', 'w');
fputcsv($fp, array("identifier", "label", "description", "label_fr", "description_fr"));
foreach ($list as $fields) {
fputcsv($fp, $fields);
}
fclose($fp);
chmod('codeListML/'.$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']);