Update fast-xml-parser

This commit is contained in:
Dennis Reimann
2022-04-19 12:41:26 +02:00
parent 2e6457ec7b
commit e1e5dfec3b
4 changed files with 33 additions and 55 deletions

36
package-lock.json generated
View File

@@ -16,9 +16,8 @@
"broken-link-checker": "0.7.8",
"browser-sync": "2.27.9",
"csso-cli": "3.0.0",
"fast-xml-parser": "3.21.1",
"fast-xml-parser": "4.0.7",
"glob": "8.0.1",
"he": "1.2.0",
"html-entities": "2.3.3",
"jstransformer-markdown-it": "2.1.0",
"markdown-it": "12.3.2",
@@ -2015,15 +2014,15 @@
}
},
"node_modules/fast-xml-parser": {
"version": "3.21.1",
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.21.1.tgz",
"integrity": "sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==",
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.0.7.tgz",
"integrity": "sha512-dMtibyus3kC7nbxj1CpVtysLzO13UOAZEFAb5vpQg3T4O6qvetmSePpXKFx5KPNCHKoGwjtgjfF5DOyn7s1ylQ==",
"dev": true,
"dependencies": {
"strnum": "^1.0.4"
"strnum": "^1.0.5"
},
"bin": {
"xml2js": "cli.js"
"fxparser": "src/cli/cli.js"
},
"funding": {
"type": "paypal",
@@ -2407,15 +2406,6 @@
"node": ">=8"
}
},
"node_modules/he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dev": true,
"bin": {
"he": "bin/he"
}
},
"node_modules/hosted-git-info": {
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",
@@ -8240,12 +8230,12 @@
}
},
"fast-xml-parser": {
"version": "3.21.1",
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-3.21.1.tgz",
"integrity": "sha512-FTFVjYoBOZTJekiUsawGsSYV9QL0A+zDYCRj7y34IO6Jg+2IMYEtQa+bbictpdpV8dHxXywqU7C0gRDEOFtBFg==",
"version": "4.0.7",
"resolved": "https://registry.npmjs.org/fast-xml-parser/-/fast-xml-parser-4.0.7.tgz",
"integrity": "sha512-dMtibyus3kC7nbxj1CpVtysLzO13UOAZEFAb5vpQg3T4O6qvetmSePpXKFx5KPNCHKoGwjtgjfF5DOyn7s1ylQ==",
"dev": true,
"requires": {
"strnum": "^1.0.4"
"strnum": "^1.0.5"
}
},
"fastq": {
@@ -8534,12 +8524,6 @@
"type-fest": "^0.8.0"
}
},
"he": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/he/-/he-1.2.0.tgz",
"integrity": "sha512-F/1DnUGPopORZi0ni+CvrCgHQ5FyEAHRLSApuYWMmrbSwoN2Mn/7k+Gl38gJnR7yyDZk6WLXwiGod1JOWNDKGw==",
"dev": true
},
"hosted-git-info": {
"version": "2.8.9",
"resolved": "https://registry.npmjs.org/hosted-git-info/-/hosted-git-info-2.8.9.tgz",

View File

@@ -48,9 +48,8 @@
"broken-link-checker": "0.7.8",
"browser-sync": "2.27.9",
"csso-cli": "3.0.0",
"fast-xml-parser": "3.21.1",
"fast-xml-parser": "4.0.7",
"glob": "8.0.1",
"he": "1.2.0",
"html-entities": "2.3.3",
"jstransformer-markdown-it": "2.1.0",
"markdown-it": "12.3.2",

View File

@@ -1,3 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:anchor="https://anchor.fm/xmlns" xmlns:podcast="https://podcastindex.org/namespace/1.0">
<channel>
<podcast:value type="lightning" method="keysend">

View File

@@ -4,10 +4,8 @@ const { replacements, slugify, stripHTML } = require('../helpers')
const { masterFeedUrl, publicFeedUrl } = require('../content/meta.json')
const nodes = require('../content/nodes.json')
const request = require('sync-request')
const parser = require('fast-xml-parser')
const JSON2XMLParser = require('fast-xml-parser').j2xParser
const { XMLParser, XMLBuilder, XMLValidator } = require('fast-xml-parser')
const xmlFormat = require('xml-formatter')
const he = require('he')
const debug = process.env.CI
const dir = resolve(__dirname, '..')
@@ -16,37 +14,28 @@ const writeJSON = (name, data) => write(`generated/${name}.json`, JSON.stringify
const commonOpts = {
attributeNamePrefix: '',
attrNodeName: '__attr',
textNodeName: '#text',
attributesGroupName: '__attr',
ignoreAttributes: false,
cdataTagName: '__cdata',
cdataPositionChar: '\\c'
cdataPropName: '__cdata'
}
const xml2jsonOpts = {
...commonOpts,
ignoreNameSpace: false,
parseNodeValue: true,
parseTagValue: true,
parseAttributeValue: false,
trimValues: true,
parseTrueNumberOnly: false,
arrayMode: false,
numParseOptions: {
hex: true,
leadingZeros: true,
},
tagValueProcessor: val => he.decode(val),
attrValueProcessor: val => he.decode(val, { isAttributeValue: true })
arrayMode: false
}
var json2xmlOpts = {
const json2xmlOpts = {
...commonOpts,
format: false,
indentBy: ' ',
supressEmptyNode: false,
tagValueProcessor: a => a,
attrValueProcessor: a => he.encode(a, { isAttributeValue: true, useNamedReferences: true })
};
processEntities: false
}
const parser = new XMLParser(xml2jsonOpts, true)
const builder = new XMLBuilder(json2xmlOpts)
const parseEpisode = e => {
const guid = e.guid['#text']
@@ -86,7 +75,7 @@ const parseEpisode = e => {
<podcast:valueRecipient type="node" split="20" name="Daniel" address="${nodes.daniel}" />
</podcast:value>`)
const feed = parser.parse(xml, xml2jsonOpts, true)
const feed = parser.parse(xml)
const episodes = []
const _noParticipants = [], _noNode = []
@@ -136,12 +125,17 @@ const parseEpisode = e => {
writeJSON('feed', feed)
const JSON2XML = new JSON2XMLParser(json2xmlOpts)
const outputXML = JSON2XML.parse(feed)
const outputXML = builder.build(feed)
writeJSON('episodes', episodes)
write('dist/feed.xml', xmlFormat(outputXML, { indentation: ' ', collapseContent: true }))
write('static/feed.xml', xmlFormat(outputXML, { indentation: ' ', collapseContent: true }))
const validation = XMLValidator.validate(outputXML)
if (validation) {
write('dist/feed.xml', xmlFormat(outputXML, { indentation: json2xmlOpts.indentBy, collapseContent: true }))
write('static/feed.xml', xmlFormat(outputXML, { indentation: json2xmlOpts.indentBy, collapseContent: true }))
} else {
console.error(validation.err)
}
if (_noParticipants.length) {
console.log('Keine Teilnehmerliste')