forked from MapGIS/WebClient-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXML.js
More file actions
54 lines (50 loc) · 1.14 KB
/
XML.js
File metadata and controls
54 lines (50 loc) · 1.14 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
/**
* @module ol/format/XML
*/
import {isDocument, parse} from './util/xml.js';
/**
* @classdesc
* Generic format for reading non-feature XML data
*
* @abstract
*/
class XML {
/**
* Read the source document.
*
* @param {Document|Element|string} source The XML source.
* @return {Object} An object representing the source.
* @api
*/
read(source) {
if (!source) {
return null;
} else if (typeof source === 'string') {
const doc = parse(source);
return this.readFromDocument(doc);
} else if (isDocument(source)) {
return this.readFromDocument(/** @type {Document} */ (source));
} else {
return this.readFromNode(/** @type {Element} */ (source));
}
}
/**
* @param {Document} doc Document.
* @return {Object} Object
*/
readFromDocument(doc) {
for (let n = doc.firstChild; n; n = n.nextSibling) {
if (n.nodeType == Node.ELEMENT_NODE) {
return this.readFromNode(/** @type {Element} */ (n));
}
}
return null;
}
/**
* @abstract
* @param {Element} node Node.
* @return {Object} Object
*/
readFromNode(node) {}
}
export default XML;