How to use the xml-js.xml2json function in xml-js

To help you get started, we’ve selected a few xml-js examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github csegames / Camelot-Unchained / game / hud / src / components / fullscreen / AbilityBuilder / AbilityCreation / IconPicker.tsx View on Github external
private initializeIcons = async () => {
    const res = await request('get', ICONS_URL);

    // Comes in as xml. Need to convert to json.
    const data = JSON.parse(convert.xml2json(res.data));
    const icons: string[] = [];
    const elements = data.elements[0].elements;
    elements.slice(5, elements.length).forEach((element: any) => {
      icons.push('http://camelot-unchained.s3.amazonaws.com/' + element.elements[0].elements[0].text);
    });
    this.setState({ icons, loading: false });
  }
github crablar / podsheets / server / src / routes / podcasts.ts View on Github external
categories,
                    author: fullOwnerName,
                    date: e.createdAt.toISOString(),
                    // lat: 33.417974, //optional latitude field for GeoRSS
                    // long: -111.933231, //optional longitude field for GeoRSS
                    itunesAuthor: fullOwnerName,
                    itunesExplicit: false,
                    itunesSubtitle: e.summary,
                    itunesSummary: e.summary,
                    itunesDuration: Math.trunc(e.audioDuration),
                    itunesKeywords: ["javascript", "podcast"],
                });
            });

            // We manually add iTunes category because in the podcasts module it doesn't work
            const jsonFeed = JSON.parse(convert.xml2json(feed.xml(), { compact: false, spaces: 4 }));
            jsonFeed.elements[0].elements[0].elements.push({
                type: "element",
                name: "itunes:category",
                attributes: {
                    text: mainCategory,
                },
                elements: subCategory.length > 0 ? [{
                    type: "element",
                    name: "itunes:category",
                    attributes: {
                        text: subCategory,
                    },
                }]
                    :
                    [],
            });
github steemdocs / steemdocs / tests / sitemap.js View on Github external
function getSitemap () {
  const src = path.join(__dirname, '../', '/docs/.vuepress/dist/sitemap.xml')
  const sitemapXmlContent = fs.readFileSync(src)
  return JSON.parse(convert.xml2json(sitemapXmlContent))
}
github micblo / ucenter-client / examples / xml_parser.js View on Github external
`

	
		
		
		
		
		
			
		
		
		
	
`;
const result1 = convert.xml2js(xml, {compact: true});
console.log(convert.xml2json(xml, {compact: true}));

function analyzeNode(node) {
    if (node.root) {
        return analyzeNode(node.root);
    } else if (node.item) {
        if (Array.isArray(node.item)) {
            if (/^\d+$/g.test(node.item[0]._attributes.id)) {
                return node.item.map(v => {
                    return analyzeNode(v);
                });
            } else {
                const data = {};
                node.item.forEach(v => {
                    data[v._attributes.id] = analyzeNode(v);
                });
                return data;
github SeleniumHQ / selenium-ide / packages / side-migrate / src / legacy / migrate.js View on Github external
export function migrateTestCase(data) {
  const sanitized = sanitizeXml(data)
  const result = JSON.parse(convert.xml2json(sanitized, { compact: true }))
  const baseUrl = result.html.head.link
    ? result.html.head.link._attributes.href
    : undefined
  let tr = result.html.body.table.tbody.tr
  tr = Array.isArray(tr) ? tr : [tr]
  const test = {
    name: result.html.body.table.thead.tr.td._text,
    commands: tr
      .filter(row => row.td[0]._text && isImplementedWait(row.td[0]._text))
      .map(row => ({
        command: row.td[0]._text && row.td[0]._text.replace('AndWait', ''),
        target: xmlunescape(parseTarget(row.td[1])),
        value: xmlunescape(row.td[2]._text || ''),
        comment: '',
      })),
  }
github Arva / arva-ui-kit / scripts / adjust_icon_resources.js View on Github external
"use strict";

const fs = require('fs');
const convert = require('xml-js');
const iconDirectory = './src/icons/resources';

//TODO Automate 100% width/height as well (but not the viewBox),
//and be able to handle nested directories corresponding to a concatenated underscore (when supplied by Chari)
for (let fileName of fs.readdirSync(iconDirectory)) {
    if (!fileName.endsWith('.svg')) {
        continue;
    }
    console.log(`Processing fileName: ${fileName}`);
    
    let originalXml = fs.readFileSync(`${iconDirectory}/${fileName}`, 'utf8', {compact: false});
    let iconContents = JSON.parse(convert.xml2json(originalXml));
    adjustIconDataRecursively(fileName, iconContents);
    let xml = convert.json2xml(iconContents, {compact: false, ignoreComment: true, spaces: 3});
    let newFilePath = `${iconDirectory}/${fileName}.txt`;
    fs.writeFileSync(newFilePath, xml);
}

console.log("Processing complete!")

function adjustIconDataRecursively(fileName, node) {

    let attributes = node.attributes, children = node.elements;
    if(node.name === 'svg'){
        node.attributes.width = '100%';
        node.attributes.height = '100%';
    }
github torreyleonard / algotrader / objects / data / News.js View on Github external
}, (error, response, body) => {
				if (error) reject(error);
				else if (response.statusCode !== 200) reject(new LibraryError(body));
				else {
					const result = JSON.parse(xmlJS.xml2json(body, {compact: true, spaces: 0})).rss.channel.item;
					let array = [];
					result.forEach(o => {
						array.push(new News({
							title: o.title._text,
							description: o.description._text,
							date: new Date(o.pubDate._text),
							url: o.link._text
						}))
					});
					resolve(array);
				}
			})
		})
github assimbly / gateway / src / main / webapp / app / entities / flow / flow-editor-mode.component.ts View on Github external
}, (err) => {
                let convert = require('xml-js');
                let obj = JSON.parse(convert.xml2json(err.text(), { compact: true, spaces: 4 }));
                let errMessage = obj.response.message._text;
                this.showInfoMessage(false, errMessage);
            }));
github SeleniumHQ / selenium-ide / packages / side-migrate / src / legacy / migrate.js View on Github external
function migrateSuite(suite, fileMap, project) {
  const result = JSON.parse(convert.xml2json(fileMap[suite], { compact: true }))
  const parsedSuite = {
    id: suite,
    name: result.html.head.title._text,
    tests: [],
  }
  project.suites.push(parsedSuite)
  result.html.body.table.tbody.tr.forEach(testCase => {
    if (testCase.td.a) {
      const testCaseName = testCase.td.a._attributes.href
      if (!fileMap[testCaseName]) {
        throw new Error(
          `The file ${testCaseName} is missing, suite can't be migrated`
        )
      }
      parsedSuite.tests.push(testCaseName)
      project.name = parsedSuite.name
github dbsystel / 1BahnQL / Timetable / TimetableLoader.js View on Github external
.then(result => {
        const options = { ignoreComment: true, alwaysChildren: true };
        return JSON.parse(convert.xml2json(result, options));
      });
  }

xml-js

A convertor between XML text and Javascript object / JSON text.

MIT
Latest version published 6 years ago

Package Health Score

65 / 100
Full package analysis