2020-06-29 00:35:18 +09:00
|
|
|
const parseXml = xmlString => {
|
2020-06-28 06:33:20 +09:00
|
|
|
const codeCollection = new DOMParser()
|
2020-06-29 00:35:18 +09:00
|
|
|
.parseFromString(xmlString, 'text/xml')
|
|
|
|
.getElementsByTagName('code');
|
2020-06-28 06:33:20 +09:00
|
|
|
|
|
|
|
const codes = [...codeCollection];
|
|
|
|
|
2020-06-29 00:35:18 +09:00
|
|
|
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, ''),
|
2020-06-28 06:33:20 +09:00
|
|
|
}));
|
|
|
|
};
|
|
|
|
|
2020-06-29 00:35:18 +09:00
|
|
|
const parseTextNode = (node, identifier) => node.getElementsByTagName(identifier)[0].textContent;
|
2020-06-28 06:33:20 +09:00
|
|
|
|
|
|
|
export default parseXml;
|