|
1 |
| -const xml = require('simple-xml-dom'); |
2 |
| -const xpath = require('xpath'); |
| 1 | +const findTagByPath = require('xml-utils/src/find-tag-by-path'); |
| 2 | + |
3 | 3 |
|
4 | 4 | const parseISO = metadata => {
|
5 | 5 | const results = {};
|
6 | 6 |
|
7 |
| - const dom = xml.parse(metadata); |
8 |
| - |
9 |
| - const select = xpath.useNamespaces({ |
10 |
| - gco: 'http://www.isotc211.org/2005/gco', |
11 |
| - gmd: 'http://www.isotc211.org/2005/gmd', |
12 |
| - }); |
13 |
| - |
14 | 7 | try {
|
15 |
| - results.projection = parseFloat(select('string(//gmd:RS_Identifier//gmd:code//gco:CharacterString/text())', dom)); |
| 8 | + results.projection = parseFloat(findTagByPath(metadata, ['gmd:RS_Identifier', 'gmd:code', 'gco:CharacterString']).inner); |
16 | 9 | } catch (error) {
|
17 | 10 | console.error(error);
|
18 | 11 | }
|
19 | 12 |
|
20 | 13 | try {
|
21 |
| - results.xmin = parseFloat(select('string(//gmd:westBoundLongitude//gco:Decimal/text())', dom)); |
22 |
| - results.xmax = parseFloat(select('string(//gmd:eastBoundLongitude//gco:Decimal/text())', dom)); |
23 |
| - results.ymin = parseFloat(select('string(//gmd:southBoundLatitude//gco:Decimal/text())', dom)); |
24 |
| - results.ymax = parseFloat(select('string(//gmd:northBoundLatitude//gco:Decimal/text())', dom)); |
| 14 | + results.xmin = parseFloat(findTagByPath(metadata, ['gmd:westBoundLongitude', 'gco:Decimal']).inner); |
| 15 | + results.xmax = parseFloat(findTagByPath(metadata, ['gmd:eastBoundLongitude', 'gco:Decimal']).inner); |
| 16 | + results.ymin = parseFloat(findTagByPath(metadata, ['gmd:southBoundLatitude', 'gco:Decimal']).inner); |
| 17 | + results.ymax = parseFloat(findTagByPath(metadata, ['gmd:northBoundLatitude', 'gco:Decimal']).inner); |
25 | 18 | } catch (error) {
|
26 | 19 | console.error(error);
|
27 | 20 | }
|
28 | 21 |
|
29 |
| - console.log('results:', results); |
30 |
| - |
31 | 22 | return results;
|
32 | 23 | };
|
33 | 24 |
|
|
0 commit comments