gctGenerator/docs/.vuepress/components/scripts/parseXml.js
Matteias Collet b7bea697be init vuepress
2020-06-29 23:31:44 +02:00

21 lines
655 B
JavaScript

const parseXml = (xmlString) => {
const codeCollection = new DOMParser()
.parseFromString(xmlString, "text/xml")
.getElementsByTagName("code");
const codes = [...codeCollection];
return codes.map((code) => ({
author: parseTextNode(code, "author"),
title: parseTextNode(code, "title"),
description: parseTextNode(code, "description"),
version: parseTextNode(code, "version"),
date: parseTextNode(code, "date"),
source: parseTextNode(code, "source").replace(/[\s\n\r\t]+/gm, ""),
}));
};
const parseTextNode = (node, identifier) =>
node.getElementsByTagName(identifier)[0].textContent;
export default parseXml;