How to use the x2js function in x2js

To help you get started, we’ve selected a few x2js 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 Phyks / ampache_react / app / middleware / api.js View on Github external
function _parseToJSON(responseText) {
    let x2js = new X2JS({
        attributePrefix: "",  // No prefix for attributes
        keepCData: false,  // Do not store __cdata and toString functions
    });
    if (responseText) {
        return x2js.xml_str2json(responseText).root;
    }
    return Promise.reject(new i18nRecord({
        id: "app.api.invalidResponse",
        values: {},
    }));
}
github bkorobeinikov / movieapp-ionic / src / core / base.service.ts View on Github external
private parseResponse(res: Response) {
        console.log("response", res);

        let contentType = res.headers.get("Content-Type");
        if (contentType.indexOf("application/json") > -1) {
            return res.json();
        } else if (
            contentType.indexOf("application/xml") > -1 ||
            contentType.indexOf("text/xml") > -1) {
            var x2js = new X2JS();
            var text = res.text();
            var jsonObj: any = x2js.xml2js(text);
            jsonObj = jsonObj[Object.keys(jsonObj)[0]];

            return jsonObj;
        }

        throw new Error("Unsupported response content type - " + contentType);
    }
github knreise / KNReiseAPI / src / apis / KSamsokAPI.js View on Github external
function _parseItems(response) {

        var x2js = new X2JS();
        var json = x2js.xml2json(response);

        var features = _.chain(json.result.records.record)
            .map(_parseRecord)
            .filter(function (feature) {
                return !!feature;
            })
            .value();
        return createFeatureCollection(features);
    }
github UCL-INGI / StudUCLouvain / src / providers / studies-services / ade-service.ts View on Github external
convertXmlToJson(xml) : any{
    let parser : any = new X2JS();
    let json = parser.xml2js(xml);
    return json;
  }
github UCL-INGI / StudUCLouvain / src / providers / rss-services / rss-service.ts View on Github external
convertXmlToJson(xml) : any{
      let parser : any = new X2JS();
      let json = parser.xml2js(xml);
      return json;
    }
github knreise / KNReiseAPI / src / apis / KSamsokAPI.js View on Github external
function _parseItem(response) {
        var x2js = new X2JS();
        var json = x2js.xml2json(response);
        var item = json.RDF.Description[0].presentation.item;
        var image;
        if (_.has(item, 'image')) {
            var img = _.find(item.image.src, function (src) {
                return src._type === 'lowres';
            });
            if (img) {
                image = img.__text;
            }
        }
        return {
            itemDescription: item.description.__text,
            image: image
        };
    }
github F4b1n0u / my-games / app / services / amazon.js View on Github external
.map((response) => {
      const xmlResponse = response.response
      const jsonResponse = new X2JS().xml2js(xmlResponse)
      let gameName = _.get(jsonResponse, 'ItemSearchResponse.Items.Item.ItemAttributes.Title', '')
      gameName = gameName.replace(/\([^()]*\)/g, '')
      return gameName
    })
}

x2js

Transforms between XML string and JavaScript object trees.

Apache-2.0
Latest version published 2 years ago

Package Health Score

59 / 100
Full package analysis

Popular x2js functions