How to use the xml2js function from xml-js
Find comprehensive JavaScript xml-js.xml2js code examples handpicked from public code repositorys.
71 72 73 74 75 76 77 78 79 80
async getContent_() { /** @const {StorageFileConfig} */ const { bucket, name, projectId } = this.config.source; const xml = await StorageFile.getInstance(bucket, name, { projectId: this.getCloudProject() }).loadContent(0); const data = xml2js(xml, { compact: true }); const items = data.rss.channel.item.map((item) => { const result = {}; Object.keys(item).forEach((key) => { const keyFragments = key.split(':');
74
143
33
+ 10 other calls in file
GitHub: iotux/ElWiz
145 146 147 148 149 150 151 152 153 154
let url = entsoeUrl(token, entsoeDate(dayOffset), entsoeDate(dayOffset + 1)); let fileName = savePath + '/prices-' + skewDays(dayOffset) + '.json'; let redisKey = "prices-" + skewDays(dayOffset); await request.get(url, reqOpts).then(function (body) { let result = convert.xml2js(body.data, { compact: true, spaces: 4 }); if (result.Publication_MarketDocument !== undefined) { let realMeat = result.Publication_MarketDocument.TimeSeries.Period; let startDay = getDate(realMeat.timeInterval.start._text); let endDay = getDate(realMeat.timeInterval.end._text);
14
88
2
+ 7 other calls in file
333 334 335 336 337 338 339 340 341 342 343
const fetchAvailableWeatherStations = (callback) => { axios.get("https://dd.weather.gc.ca/citypage_weather/xml/siteList.xml").then((resp) => { const data = resp.data; if (!data) return; const options = xml2js(data, { compact: true }); if (!options || !options.siteList || !options.siteList.site) { if (typeof callback === "function") callback(false); throw "Unable to parse siteList"; }
3
17
3
+ 6 other calls in file
21 22 23 24 25 26 27 28 29 30
* Build the global metadata dictionary * * @param meta */ const loadMetadata = (meta) => { const xml = convert.xml2js(meta, { compact: false }); if (xml.elements.length !== 1) { throw new Error("Oops looks like this is not a bundle... "); } if (xml.elements[0].name !== "bundle") {
6
12
3
+ 9 other calls in file
GitHub: LibreTexts/Libretext
2097 2098 2099 2100 2101 2102 2103 2104 2105 2106
async function getSitemap() { let map = await fetch(`https://${subdomain}.libretexts.org/sitemap.xml`); if (map.ok) { map = await map.text(); map = convert.xml2js(map).elements[0]; } else { let error = await map.text(); console.error(error);
8
11
6
+ 17 other calls in file
GitHub: iLib-js/loctool
621 622 623 624 625 626 627 628 629 630
* units already in this instance, they will be removed first. * * @param {String} xml the tmx format text to parse */ Tmx.prototype.deserialize = function(xml) { var json = xmljs.xml2js(xml, { trim: false, nativeTypeAttribute: true, compact: true });
4
10
8
+ 6 other calls in file
GitHub: peakresponse/peak-server
118 119 120 121 122 123 124 125 126 127
headers: { 'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1', }, }); const xml = await response.text(); const json = xmljs.xml2js(xml, { compact: true }); for (const item of json.rss.channel.item) { const article = { title: item.title._cdata, pubDate: moment(item.pubDate._text).format('MMMM D, YYYY'),
0
1
3
+ 11 other calls in file
226 227 228 229 230 231 232 233 234 235
let trackAnreise = await getSequenceFromFile(fileAnreise); let trackAbreise = await getSequenceFromFile(fileAbreise); try { if(!!fileMain){ const fileContent = await fs.readFile(fileMain, 'utf-8'); let json = convertXML.xml2js(fileContent); if(json && json.elements.length > 0 && json.elements[0].elements){ if(!!trackAnreise && trackAnreise.elements){ json.elements[0].elements.splice(0, 0, trackAnreise ); }
1
0
2
+ 9 other calls in file
821 822 823 824 825 826 827 828 829 830
// this.logger.debug("Extracting strings from " + this.pathName); this.xml = data; this.resourceIndex = 0; this.json = xmljs.xml2js(data, { trim: false, nativeTypeAttribute: true, compact: true });
0
0
2
+ 5 other calls in file
14 15 16 17 18 19 20 21 22 23
const res = await axios.get(fullUrl).catch(e => { let error = e.toJSON(); throw new Error(`Server returned status ${error.status} for URL ${fullUrl}`); }); let converted = convert.xml2js(res.data, { compact: true }); delete converted._declaration; return converted;
0
0
1
+ 8 other calls in file
59 60 61 62 63 64 65 66 67 68
if(typeof req.body.format!="undefined"&&req.files.length == 1) { try { let data switch(req.body.format) { case "xml": data = xmljs.xml2js(req.files[0].data.toString("utf-8"), {compact: true}) if(!(typeof data["automatic-deployment"]!= 'undefined' && typeof data["enclaves"]!="undefined")) throw new Error("Conversion failed") configInstance.mainConfig.essential = data configInstance.saveConfigAsync() break;
0
0
1
GitHub: CPeluti/parserGMXML
97 98 99 100 101 102 103 104 105 106
output += '</root>\n</mxGraphModel>\n</diagram>\n</mxfile>' fs.writeFileSync(pathOutput, output) } function convertDIOXML2GM(pathInput, pathOutput){ const f = fs.readFileSync(pathInput, {encoding:'utf8'}) let gm = parser.xml2js(f) gm = gm.elements[0].elements[0].elements[0] const size = [parseInt(gm.attributes.pageWidth), parseInt(gm.attributes.pageHeight)] const nodes = gm.elements[0].elements const parsedGm = {actors: [], orphans:[], dependencies:[], links:[], display: [], diagram: {width:size[0], height: size[1]}}
0
0
0
xml-js.xml2js is the most popular function in xml-js (101 examples)