isoxml-angular
Version:
JavaScript library to parse and generate ISOXML (ISO11783-10) files
40 lines (39 loc) • 1.33 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.xml2js = exports.js2xml = void 0;
const fast_xml_parser_1 = require("fast-xml-parser");
const XML_PARSE_OPTIONS = {
textNodeName: '_text',
attributeNamePrefix: '',
ignoreAttributes: false,
attributesGroupName: '_attributes',
parseTagValue: false,
parseAttributeValue: false,
isArray: (tagName, jPath, isLeafNode, isAttribute) => !isAttribute,
attributeValueProcessor: (name, value) => value.replace(/&/g, '&')
.replace(/'/g, "'")
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
};
const XML_BUILD_OPTIONS = {
textNodeName: '_text',
attributeNamePrefix: '',
ignoreAttributes: false,
attributesGroupName: '_attributes',
format: true,
attributeValueProcessor: (name, value) => value.replace(/&/g, '&')
.replace(/'/g, ''')
.replace(/"/g, '"')
.replace(/</g, '<')
.replace(/>/g, '>')
};
function js2xml(json) {
return `<?xml version="1.0" encoding="UTF-8"?>
${new fast_xml_parser_1.XMLBuilder(XML_BUILD_OPTIONS).build(json)}`;
}
exports.js2xml = js2xml;
function xml2js(xml) {
return new fast_xml_parser_1.XMLParser(XML_PARSE_OPTIONS).parse(xml);
}
exports.xml2js = xml2js;