How to use the fast-xml-parser.validate 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 matrix-org / matrix-bifrost / test / xmppjs / test_Stanzas.ts View on Github external
function assertXML(xml) {
    const err = parser.validate(xml);
    if (err !== true) {
        // console.error(xml);
        throw new Chai.AssertionError(err.err.code + ": " + err.err.msg);
    }
}
github BrainJS / brain.js / __tests__ / utilities / to-svg.js View on Github external
it('should return valid xml when sane inputs provided', () => {
      expect(parser.validate(toSVG(network, options))).toBe(true);
    });
  });
github stoplightio / prism / test-harness / helpers.ts View on Github external
test: (contentType: string, content: string) => {
    const doesContentTypeMatch = !!typeIs.is(contentType, [
      'application/xml',
      'application/*+xml',
      'text/xml',
    ]);
    const isContentXML = parser.validate(content) === true;

    return doesContentTypeMatch || isContentXML;
  },
  validate: (expected: Result, output: Result) => {
github NaturalIntelligence / Stubmatic / index.js View on Github external
function validateSyntax(fileName) {
	try {
		if (fileName.endsWith(".json")) {
			require('jsonlint').parse(fs.readFileSync(fileName, {
				encoding: 'utf-8'
			}));
			console.log("Validated successfully");
		} else if (fileName.endsWith(".yaml") || fileName.endsWith(".yml")) {
			require('yamljs').parseFile(fileName);
			console.log("Validated successfully");
		}else if(fileName.endsWith(".xml")){
			var result = require('fast-xml-parser').validate(fs.readFileSync(fileName, {
				encoding: 'utf-8'
			}));
			if(result === true) {
				console.log("Validated successfully");
			}else{
				console.log("Validation failed");
			}
		}else {
			console.log("Unsupported file");
		}
	} catch (e) {
		console.log("Validation failed");
		console.log(color(e, 'red'));
		//if(e.line) console.log("line number: " + e.line + ":" + e.column);
	}
}
github AnyChart / AnyChart-NodeJS / lib / anychart-node.js View on Github external
if (typeof options === 'string') {
    params.outputType = options;
  } else if (typeof options === 'object') {
    extend(params, options)
  }

  var target = args[0];
  if (target && !isDef(params.dataType)) {
    if (typeof target === 'string') {
      target = target.replace(/^[\s\xa0]+|[\s\xa0]+$/g, '');

      try {
        JSON.parse(target);
        params.dataType = 'json';
      } catch (e) {
        if (fastXmlParser.validate(target)) {
          if (target.lastIndexOf('
github Vachounet / android_helper_bot / handlers / crdroid.js View on Github external
function (error, response, body) {
                if (parser.validate(body)) {
                    var jsonObj = parser.parse(body);

                    var device;
                    for (var i = 0; i < jsonObj.OTA.manufacturer.length; i++) {
                        if (jsonObj.OTA.manufacturer[i][keywords]) {
                            device = jsonObj.OTA.manufacturer[i][keywords];
                            break;
                        }
                    }

                    if (device) {
                        
                            request.get(device.download, {
                                    followRedirect: false
                                },
                                function (error, response, body) {
github VoxaAI / voxa / src / VoxaReply.ts View on Github external
export function addToSSML(ssml: string|undefined, statement: string): string {
  let reply: string;

  ssml = ssml || "";
  const base = ssml.replace(/^([\s\S]*)<\/speak>$/g, "$1");

  statement = statement.replace(/&/g, "&");

  if (!base) {
    reply =  `${statement}`;
  } else {
    reply =  `${base}\n${statement}`;
  }

  const validationResult = parser.validate(reply);

  if (validationResult === true) {
    return reply;
  }

  throw new SSMLError(validationResult.err.msg, reply);
}
github camunda / camunda-bpm-sdk-js / lib / forms / type-util.js View on Github external
var isValidXML = function(value) {
  return value ? xmlParser.validate(value) : false;
};

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