How to use the xml2js.Builder function in xml2js

To help you get started, we’ve selected a few xml2js 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 hyurl / cool-node / Core / Middleware / HttpXMLHandler.js View on Github external
const bodyParser = require('body-parser');
const xml2js = require("xml2js");

var plain = /text\/plain\b/,
    xml = /(text|application)\/xml\b/,
    builder = new xml2js.Builder({ cdata: true });

module.exports = (app) => {
    app.use(bodyParser.text({
        type: (req) => {
            // Parse plain/XML.
            var type = req.headers['content-type'];
            return plain.test(type) || xml.test(type);
        }
    })).use((req, res, next) => {
        // Add a method on response object, used for sending XML to the client.
        res.xml = (data) => {
            if (!res.get("Content-Type")) {
                res.type("xml");
            }
            if (data !== null && data !== undefined) {
                if (typeof data == "string") {
github boopathi / react-svg-loader / index.js View on Github external
module.exports = function(content) {

  this.cacheable && this.cacheable(true);
  this.addDependency(this.resourcePath);

  var loaderContext = this;
  var callback = this.async();

  var parser = new xml2js.Parser({
    normalize: true,
    normalizeTags: true
  });

  var builder = new xml2js.Builder({
    headless: true
  });

  parser.addListener('error', function(err) {
    callback(err);
  });

  parser.addListener('end', function(result) {
    var svg = result.svg;
    var allowedAttrs = ['d', 'id', 'width', 'height', 'style'];
    // $ is the list of attrs
    var allowedTags = svgElements.concat(['$']);
    var filtered = traverse(result, function(value, key, parent, parentKey) {
      if ('number' === typeof key) return true;
      if (parentKey === '$') return allowedAttrs.indexOf(key) > -1;
      return allowedTags.indexOf(key) > -1;
github NativeScript / nativescript-cli / lib / services / android-plugin-build-service.ts View on Github external
packageName = xml["manifest"]["$"]["package"];
			}

			// set the xml as the value to iterate over its properties
			xml = xml["manifest"];
		}

		// if the manifest file doesn't have a  scope, only the first setting will be picked up
		const newManifest: any = { manifest: {} };
		for (const prop in xml) {
			newManifest.manifest[prop] = xml[prop];
		}

		newManifest.manifest["$"]["package"] = packageName;

		const xmlBuilder = new Builder();
		const newManifestContent = xmlBuilder.buildObject(newManifest);

		return newManifestContent;
	}
github vobu / ui5-codecompletion / lib / helpers.js View on Github external
addEntryToXmlFileAt(aObjectsToAdd, sFileName, sFallbackFile) {
        let oParser = new xml2js.Parser();
        let builder = new xml2js.Builder();
        if (!fs.existsSync(sFileName)) {
            let sTargetDir = require('path').dirname(sFileName);
            fs.ensureDirSync(sTargetDir);

            if (fs.existsSync(sFallbackFile)) {
                fs.writeFileSync(sFileName, fs.readFileSync(sFallbackFile));
            } else {
                console.error(`fallbackfile ${sFallbackFile} does not exist - 
sure we're working a WebStorm project dir here!?`);
            }
        } else {
            let sIdeaModules = fs.readFileSync(sFileName, 'utf8');

            oParser.parseString(sIdeaModules, function (err, result) {

                _.forEach(aObjectsToAdd, function (oObject) {
github ElemeFE / element-angular / build / bin / elements-update.locale.js View on Github external
const { utils, request, apis } = require('./base')
const xml2js = require('xml2js')
const xmlParser = new xml2js.Parser({
  explicitArray: false,
  ignoreAttrs: false,
})
const parseString = utils.promisify(xmlParser.parseString)
const jsonBuilder = new xml2js.Builder({
  xmldec: {
    encoding: 'utf-8',
    standalone: true,
  },
  allowSurrogateChars: true,
  cdata: true,
})

;(async() => {
  console.log('Making messages.xlf...')
  require('child_process').spawn('npm', ['run', 'i18n'])
  
  const localSourcePath = `${__dirname}/../../ex/messages.xlf`
  const saveUnits = async(next) => {
    const file = await utils.readFile(localSourcePath)
    const result = await parseString(file)
github microsoft / generator-azuresfcsharp / generators / CoreCLRStatefulService / index.js View on Github external
parser.parseString(data, function (err, result) {
          if (err) {
              return console.log(err);
          }
          result['ApplicationManifest']['ServiceManifestImport'][result['ApplicationManifest']['ServiceManifestImport'].length] =
             {"ServiceManifestRef":[{"$":{"ServiceManifestName":servicePackage, "ServiceManifestVersion":"1.0.0"}}]}
          result['ApplicationManifest']['DefaultServices'][0]['Service'][result['ApplicationManifest']['DefaultServices'][0]['Service'].length] =
             {"$":{"Name":serviceName},"StatefulService":[{"$":{"ServiceTypeName":serviceTypeName,"InstanceCount":"1"},"SingletonPartition":[""]}]};

      var builder = new xml2js.Builder();
      var xml = builder.buildObject(result);
          fs.writeFile(path.join(appPackage , appPackagePath, 'ApplicationManifest.xml'), xml, function(err) {
            if(err) {
                return console.log(err);
            }
          }); 
        });
      });
github pterodactyl / daemon / src / helpers / fileparser.js View on Github external
}, () => {
                    const Builder = new Xml.Builder({
                        headless: headless === true,
                    });
                    Fs.writeFile(this.server.path(file), Builder.buildObject(result), 'utf8', next);
                });
            });
github longzheng / mypal-ionic / hooks / remove_android_external_storage.js View on Github external
function jsToXmlFile(filename, obj, cb) {
        var filepath = path.normalize(path.join(filename));
        var builder = new xml2js.Builder();
        var xml = builder.buildObject(obj);
        fs.writeFile(filepath, xml, cb);
    }