How to use the xmldom.DOMParser.prototype function in xmldom

To help you get started, we’ve selected a few xmldom 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 jindw / xmldom / test / index.js View on Github external
return result;
}
function check(data,doc){
	var domjsresult = format(data);
	var xmldomresult = new XMLSerializer().serializeToString(doc);
	var xmldomresult2 = new XMLSerializer().serializeToString(doc.cloneNode(true));
	assert.equal(xmldomresult,xmldomresult2);
	xmldomresult = xmldomresult.replace(/^<\?.*?\?>\s*|/g,'')
	domjsresult = domjsresult.replace(/^<\?.*?\?>\s*|/g,'')
	//console.log('['+xmldomresult+'],['+domjsresult+']')
	if(xmldomresult!=domjsresult){
		assert.equal(format(xmldomresult),domjsresult);
	}
	
}
DOMParser.prototype.parseFromString = function(data,mimeType){
	var doc = oldParser.apply(this,arguments);
	function ck(){
		if(!/\/x?html?\b/.test(mimeType)){
			try{
			check(data,doc);
			}catch(e){console.dir(e)}
		}
	}
	if(this.options.checkLater){
	setTimeout(ck,1);
	}else{ck()}
	return doc;
}
function include(){
	for(var i=0;i
github jindw / xmldom / test / index.js View on Github external
var XMLSerializer = require('xmldom').XMLSerializer;
var DOMParser = require('xmldom').DOMParser;
try{
	var libxml = require('libxmljs');
}catch(e){
	var DomJS = require("dom-js");
}

var assert = require('assert');
var oldParser = DOMParser.prototype.parseFromString ;
function format(s){
	if(libxml){
		var result = libxml.parseXmlString(s).toString().replace(/^\s+|\s+$/g,'');
		//console.log(result.charCodeAt().toString(16),result)
	}else{
		var domjs = new DomJS.DomJS();
		domjs.parse(s, function(err, dom) {
	  	  result = dom.toXml();
		});
	}
	return result;
}
function check(data,doc){
	var domjsresult = format(data);
	var xmldomresult = new XMLSerializer().serializeToString(doc);
	var xmldomresult2 = new XMLSerializer().serializeToString(doc.cloneNode(true));

xmldom

A pure JavaScript W3C standard-based (XML DOM Level 2 Core) DOMParser and XMLSerializer module.

MIT
Latest version published 4 years ago

Package Health Score

64 / 100
Full package analysis