forked from lantanagroup/FHIR.js
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathxmlHelper.ts
35 lines (27 loc) · 1.04 KB
/
xmlHelper.ts
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
import * as _ from 'underscore';
export class XmlHelper {
static escapeInvalidCharacters(element) {
_.each(element.attributes, (attribute, index) => {
element.attributes[index] = element.attributes[index]
.replace(/&(?!(?:apos|quot|[gl]t|amp);|#)/g, '&');
});
if (element.type === 'text' && element.text) {
element.text = element.text
.replace(/&(?!(?:apos|quot|[gl]t|amp);|#)/g, '&');
}
_.each(element.elements, XmlHelper.escapeInvalidCharacters);
return element;
}
static unescapeInvalidCharacters(element) {
_.each(element.attributes, (attribute, index) => {
element.attributes[index] = element.attributes[index]
.replace(/&/g, '&');
});
if (element.type === 'text' && element.text) {
element.text = element.text
.replace(/&/g, '&');
}
_.each(element.elements, XmlHelper.unescapeInvalidCharacters);
return element;
}
}