How to use the fast-xml-parser.j2xParser function in fast-xml-parser

To help you get started, we’ve selected a few fast-xml-parser 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 jamhall / s3rver / lib / s3rver.js View on Github external
configureBuckets,
      ...serverOptions
    } = defaults({}, options, S3rver.defaultOptions);
    this.serverOptions = serverOptions;
    this._configureBuckets = configureBuckets;
    this.silent = silent;
    this.resetOnClose = resetOnClose;
    this.allowMismatchedSignatures = allowMismatchedSignatures;
    this.store = this.context.store = new FilesystemStore(directory);

    // Log all requests
    this.use(loggerMiddleware(this, silent));

    try {
      // encode object responses as XML
      const parser = new xmlParser.j2xParser({
        ignoreAttributes: false,
        attrNodeName: '@',
        tagValueProcessor: a => he.escape(a.toString()),
      });
      this.use(async (ctx, next) => {
        await next();
        if (isPlainObject(ctx.body)) {
          ctx.type = 'application/xml';
          ctx.body =
            '\n' + parser.parse(ctx.body);
        }
      });

      // Express mount interop
      this.use((ctx, next) => {
        ctx.mountPath = ctx.mountPath || ctx.req.baseUrl;
github XGHeaven / nos-node-sdk / src / client.ts View on Github external
protected async _request(method: string, headers: any, resource: Resource, body?: any): Promise {
    headers['date'] = new Date().toUTCString()

    const uri = getResourceUri(resource)

    // 并不知道设置错误的 content-type 会有什么影响,但是设置了就没错
    if (body) {
      if (typeof body === 'object' && body.constructor === Object) {
        body = new j2xParser({}).parse(CamelCaseObject(body))
        headers['content-type'] = 'application/xml;charset=UTF-8'
      } else {
        headers['content-type'] = mime.getType(uri) || 'application/octet-stream'
      }
    }

    if (body instanceof Buffer || typeof body === 'string') {
      headers['content-md5'] = md5sum(body)
      headers['content-length'] = headers['content-length'] || body.length
    }

    const sign = signature(this.options.accessSecret, method, headers, resource)
    headers['authorization'] = `NOS ${this.options.accessKey}:${sign}`

    return await fetch(url.resolve(this.options.endpoint, uri), {
      method,
github IrosTheBeggar / mStream / modules / sync.js View on Github external
maxConflicts: -1,
          disableSparseFiles: false,
          disableTempIndexes: false,
          paused: false,
          weakHashThresholdPct: 25,
          markerName: '.stfolder',
          copyOwnershipFromParent: false,
          modTimeWindowS: 0
        });
      }
    }
  );

  console.log(xmlObj.configuration);

  const final = (new (require("fast-xml-parser").j2xParser)({
    format:true,
    ignoreAttributes : false,
  })).parse(xmlObj);

  console.log(final);
  saveIt();
  bootProgram(program);
}
github IBM / zowe-cli-cics-deploy-plugin / src / api / BundleContent / Manifest.ts View on Github external
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBM Corp, 2019
*
*/

"use strict";

import { BundlePart, IBundlePartDataType } from "./BundlePart";
import { IHandlerParameters } from "@brightside/imperative";

import * as parser from "fast-xml-parser";

const serialiser = new parser.j2xParser({ignoreAttributes: false, attributeNamePrefix: ""});

/**
 * Interface to represent the manifest data for a CICS Bundle.
 *
 * @export
 * @interface IManifestType
 */
interface IManifestType {
  manifest: IManifestContents;
}
/**
 * Interface to represent the manifest data contents for CICS Bundle.
 *
 * @export
 * @interface IManifestContents
 */
github qiuwenwu / mm_node / node_modules / mm_expand / index.js View on Github external
function toXml(obj, format, mode) {
	var param = {
		format: format
	};
	if (mode) {
		param = {
			format: format,
			attrNodeName: "_attrs",
			textNodeName: "#text",
			cdataTagName: "_cdata"
		}
	};
	return xml = new j2xParser(param).parse(obj);
};
github IBM / zowe-cli-cics-deploy-plugin / src / api / BundleContent / NodejsappBundlePart.ts View on Github external
* https://www.eclipse.org/legal/epl-v20.html
*
* SPDX-License-Identifier: EPL-2.0
*
* Copyright IBM Corp, 2019
*
*/

"use strict";

import { BundlePart } from "./BundlePart";
import { TemplateNodejsappProfile } from "./TemplateNodejsappProfile";
import { IHandlerParameters } from "@brightside/imperative";
import * as parser from "fast-xml-parser";

const serialiser = new parser.j2xParser({ignoreAttributes: false, attributeNamePrefix: ""});

/**
 * Interface to represent the manifest data for a NODEJSAPP BundlePart.
 *
 * @export
 * @interface INodejsappType
 */
interface INodejsappType {
  nodejsapp: INodejsappContents;
}

/**
 * Interface to represent the manifest data contents for a NODEJSAPP BundlePart.
 *
 * @export
 * @interface INodejsappContents
github IrosTheBeggar / mStream / modules / sync.js View on Github external
function saveIt() {
  fs.writeFileSync(
    path.join(syncConfigPath, 'config.xml'), 
    (new (require("fast-xml-parser").j2xParser)({
      format:true,
      ignoreAttributes : false,
    })).parse(xmlObj), 
    'utf8');
}
github stoplightio / prism / packages / http-server / src / serialize.ts View on Github external
import { j2xParser } from 'fast-xml-parser';
import typeIs = require('type-is');

const xmlSerializer = new j2xParser({});

const serializers = [
  {
    test: (value: string) => !!typeIs.is(value, ['application/json', 'application/*+json']),
    serializer: JSON.stringify,
  },
  {
    test: (value: string) => !!typeIs.is(value, ['application/xml', 'application/*+xml']),
    serializer: (data: unknown) => (typeof data === 'string' ? data : xmlSerializer.parse({ xml: data })),
  },
  {
    test: (value: string) => !!typeIs.is(value, ['text/*']),
    serializer: (data: unknown) => {
      if (['string', 'undefined'].includes(typeof data)) {
        return data;
      }

fast-xml-parser

Validate XML, Parse XML, Build XML without C/C++ based libraries

MIT
Latest version published 3 months ago

Package Health Score

91 / 100
Full package analysis