forked from lantanagroup/FHIR.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathxmlHelper.js
35 lines (35 loc) · 1.35 KB
/
xmlHelper.js
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
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.XmlHelper = void 0;
class XmlHelper {
static escapeInvalidCharacters(element) {
if (!element)
return element;
Object.keys(element.attributes || {}).forEach(key => {
element.attributes[key] = element.attributes[key]
.replace(/&(?!(?:apos|quot|[gl]t|amp);|#)/g, '&');
});
if (element.type === 'text' && element.text) {
element.text = element.text
.replace(/&(?!(?:apos|quot|[gl]t|amp);|#)/g, '&');
}
(element.elements || []).forEach(element => XmlHelper.escapeInvalidCharacters(element));
return element;
}
static unescapeInvalidCharacters(element) {
if (!element)
return element;
Object.keys(element.attributes || {}).forEach(key => {
element.attributes[key] = element.attributes[key]
.replace(/&/g, '&');
});
if (element.type === 'text' && element.text) {
element.text = element.text
.replace(/&/g, '&');
}
(element.elements || []).forEach(element => XmlHelper.unescapeInvalidCharacters(element));
return element;
}
}
exports.XmlHelper = XmlHelper;
//# sourceMappingURL=xmlHelper.js.map