How to use the xmldom.DOMParser 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 noffle / latest-tweets / index.js View on Github external
request(url, function (err, res, body) {
    if (err) {
      cb(err)
    } else {
      var res = []

      var doc = new dom({errorHandler: function() {}}).parseFromString(body)

      var tweets = xpath.select('//li[contains(@class, \'js-stream-item\')]', doc)

      tweets.forEach(function (n) {
        var tweet = xpath.select('./div[contains(@class, \'tweet\')]/div[contains(@class, \'content\')]', n)[0]
        if (!tweet) {
          // bad tweet?
          return
        }
        
        var header = xpath.select('./div[contains(@class, \'stream-item-header\')]', tweet)[0]
        var body = xpath.select('*/p[contains(@class, \'tweet-text\')]/text()', tweet)[0]
        var fullname = xpath.select('.//strong[contains(@class, "fullname")]/text()', header)[0]
        if (body) body = nodeToText(body)
        var img = getImage(tweet)
github lijunle / Nancy.ViewEngines.React / Nancy.ViewEngines.React / tools / gulp / entry.js View on Github external
function buildEntryFile(file) {
  const contents = file.contents.toString();
  const doc = new DOMParser().parseFromString(contents);
  const select = xpath.useNamespaces({ 'proj': PROJ_NAMESPACE });
  const items = select(XPATH_SELECTOR, doc).map(node => node.value);
  const code = buildEntryCode(items);

  // TODO wait for new version vinyl, see wearefractal/vinyl-fs#71
  file.path = path.join(path.dirname(file.path), options.entryFileName);
  file.contents = new Buffer(code);

  return file;
}
github hyperflow-wms / hyperflow / examples / Comet / functions.js View on Github external
function partitionData(ins, outs, config, cb) {
    var xmlData = ins[0].data[0].value,
        doc = new dom().parseFromString(xmlData),
        xmlPath = "//Collection[@label='CollectionPoint']",
        nodes = xpath.select(xmlPath, doc);

    //onsole.log("DOC", doc);
    //onsole.log("INS", JSON.stringify(ins, null, 2));
    var timeWindowLength = 43200; // 12 hours

    outs[0].data = [[]];
    var t = 0, idx = 0, first = true;
    var timestamp, humidity, tref;

    nodes.forEach(function(node) {
        if (t >= timeWindowLength) {
            t -= timeWindowLength; idx += 1;
            first = true;
        }
github Olegas / dom-compare / test / test-reporter.js View on Github external
var assert = require("assert");
var xmldom = require("xmldom");
var parser = new xmldom.DOMParser();
var domCompare = require("../");
var compare = domCompare.compare;
var reporter = domCompare.GroupingReporter;

describe("Differences reporting", function(){

   describe("Grouping reporter", function(){

      it("grouping differences by source node XPath", function(){

         var doc = parser.parseFromString("");
         var doc2 = parser.parseFromString("");

         var failures = reporter.getDifferences(compare(doc, doc2));

         assert.equal(3, Object.keys(failures).length);
github yaronn / ws.js / test / unit / client / signature.js View on Github external
this.send = function(ctx, response_callback) {
      var doc = new Dom().parseFromString(ctx.request)
      callback(ctx, doc, response_callback)
    }
github kiliman / operator-mono-lig / index.js View on Github external
async function main() {
  fontName = process.argv[2];
  ligFontName = fontName.split('-').join('Lig-');

  const srcFileName = `./original/${fontName}.ttx`;
  const dstFileName = `./build/${ligFontName}.ttx`;
  console.log(`Reading original font file ${srcFileName}`);
  const xml = await fs.readFileAsync(srcFileName, 'utf-8');
  const dom = new DOMParser().parseFromString(xml);

  try {
    await processPatch('names', patchNames, dom);
    await processPatch('glyphs', patchGlyphs, dom);
    await processPatch('gpos', patchGpos, dom);
    await processPatch('gsub', patchGsub, dom);
    await processPatch('hmtx', patchHmtx, dom);
    //await processPatch('lookup', patchLookup, dom);
    await processPatch('charstrings', patchCharStrings, dom);
  } catch (err) {
    console.log(err);
  }

  console.log(`Writing ligature font file ${dstFileName}`);
  await fs.writeFileAsync(dstFileName, format(serialize(dom)));
  console.log('Done');
github codejamninja / react-gtk / generate / src / GtkGir.js View on Github external
async createDom() {
    const xml = (await fs.readFile(this.girPath)).toString();
    const parser = new DOMParser();
    const doc = parser.parseFromString(xml, 'text/xml');
    return doc.documentElement;
  }
}
github purplebamboo / font-carrier / lib / svg / easy_svg.js View on Github external
exports.normalizeSvg = function(svg, options) {

  var svgDocNode = new DOMParser().parseFromString(svgPathify(svg), 'application/xml')
  var svgNode = svgDocNode.getElementsByTagName('svg')[0]

  //解决所有的变换,生成一个path
  var path = Path.normalizePath(svgNode)

  var trans = svgpath(path)

  //根据目标viewbox进行变换
  var targetHeight = options.targetHeight

  if (targetHeight) {
    var viewObj = Viewbox.generateAmendTrans(svgNode, targetHeight)
    _.each(viewObj.transforms, function(viewTrans) {
      trans[viewTrans[0]].apply(trans, viewTrans[1])
    })
  }
github kelvinhokk / cordova-plugin-localization-strings / scripts / create_ios_strings.js View on Github external
function initIosDir(){
    if (!iosProjFolder || !iosPbxProjPath) {
        var config = fs.readFileSync("config.xml").toString();
        var configDoc = (new xmldom.DOMParser()).parseFromString(config, 'application/xml');
        var name = getValue(configDoc, "name");

        iosProjFolder =  "platforms/ios/" + name;
        iosPbxProjPath = "platforms/ios/" + name + ".xcodeproj/project.pbxproj";
    }
}
github kiliman / operator-mono-lig / index.js View on Github external
async function loadConfigAsync(name) {
  const fileName = `./ligature/${ligFontName}/${name}.xml`;
  const xml = await fs.readFileAsync(fileName, 'utf-8');
  return new DOMParser().parseFromString(xml);
}

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