fhir
Version:
Library that assists in handling FHIR resources. Supports serialization between JSON and XML, validation and FhirPath evaluation.
35 lines • 1.39 kB
JavaScript
;
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