How to use xmldom - 10 common examples

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 TEIC / romajs / test / setup.js View on Github external
global.usejsdom = (doc) => {
  // Switch document to jsdom
  const jdom = new JSDOM(new XMLSerializer().serializeToString(doc), {contentType: 'text/xml'})
  return jdom.window.document
}
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 PeculiarVentures / fortify / scripts / build / osx.ts View on Github external
const prjSettings = getDict(xml, "PROJECT_SETTINGS");
    if (!prjSettings) {
      throw new Error(`Cannot get PROJECT_SETTINGS from ${file}`);
    }
    const pkgName = getDict(prjSettings, "NAME");
    if (!pkgName) {
      throw new Error(`Cannot get NAME from ${file}`);
    }
    const name = `fortify-mac-x64-v${version.replace(/\./g, "_")}`;
    pkgName.textContent = name;

    // TODO: Set PATH to Fortify.app

    process.stdout.write(`Rewrite ${file} file\n`);
    fs.writeFileSync(file, new xmldom.XMLSerializer().serializeToString(xml));
  }
}
github ngOfficeUIFabric / ng-officeuifabric / build / scripts / update-nuget-versions.ts View on Github external
versionNode.textContent = libraryVersion;
//  update anuglar version
let angularVersionNode: any = query(
  '/nuget:package/nuget:metadata/nuget:dependencies/nuget:dependency[@id=\'AngularJS.Core\']',
  packageManifest,
  true);
angularVersionNode.setAttribute('version', deps.angularLib);
//  update fabric version
let fabricVersionNode: any = query(
  '/nuget:package/nuget:metadata/nuget:dependencies/nuget:dependency[@id=\'OfficeUIFabric\']',
  packageManifest,
  true);
fabricVersionNode.setAttribute('version', deps.officeUiFabricLib);

// save file changes
let domSerialzer: XMLSerializer = new xmldom.XMLSerializer();
fs.writeFileSync(yargs.argv[argKeys.pkg] + '/src/ng-office-ui-fabric.nuspec', domSerialzer.serializeToString(packageManifest));
github rstudio / leaflet / inst / htmlwidgets / lib / leaflet-omnivore / leaflet-omnivore.js View on Github external
// create a new feature collection parent object
    function fc() {
        return {
            type: 'FeatureCollection',
            features: []
        };
    }

    var serializer;
    if (typeof XMLSerializer !== 'undefined') {
        /* istanbul ignore next */
        serializer = new XMLSerializer();
    // only require xmldom in a node environment
    } else if (typeof exports === 'object' && typeof process === 'object' && !process.browser) {
        serializer = new (require('xmldom').XMLSerializer)();
    }
    function xml2str(str) {
        // IE9 will create a new XMLSerializer but it'll crash immediately.
        // This line is ignored because we don't run coverage tests in IE9
        /* istanbul ignore next */
        if (str.xml !== undefined) return str.xml;
        return serializer.serializeToString(str);
    }

    var t = {
        kml: function(doc) {

            var gj = fc(),
                // styleindex keeps track of hashed styles in order to match features
                styleIndex = {},
                // atomic geospatial types supported by KML - MultiGeometry is
github cascornelissen / svg-spritemap-webpack-plugin / lib / generate-svg.js View on Github external
return new Promise((resolve, reject) => {
        // No point in generating when there are no files
        if ( !files.length ) {
            return resolve();
        }

        // Initialize DOM/XML/SVGO
        const DOMParser = new xmldom.DOMParser();
        const XMLSerializer = new xmldom.XMLSerializer();
        const XMLDoc = new xmldom.DOMImplementation().createDocument(null, null, null);
        const SVGOptimizer = new svgo(merge(options.output.svgo, {
            plugins: [
                // Prevent empty var:* attributes from getting removed prematurely
                { removeEmptyAttrs: false },

                // Prevent groups from getting optimized prematurely as they may contain var:* attributes
                { moveGroupAttrsToElems: false },
                { collapseGroups: false },

                // Prevent titles from getting removed prematurely
                { removeTitle: false }
            ]
        }));

        // Create SVG element
        const svg = XMLDoc.createElement('svg');
github linkedinlabs / icon-magic / packages / @icon-magic / distribute / src / create-sprite.ts View on Github external
export function createSVGDoc(): { DOCUMENT: Document; svgEl: SVGSVGElement } {
  LOGGER.debug(`in create svg doc`);
  const DOM = new DOMImplementation();
  const doctype = DOM.createDocumentType(
    'svg',
    '-//W3C//DTD SVG 1.1//EN',
    'http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd'
  );
  const SVG_NS = 'http://www.w3.org/2000/svg';
  // Create an SVG Document and set its doctype
  const DOCUMENT = DOM.createDocument(SVG_NS, 'svg', doctype);
  // Create SVG element
  const svgEl = DOCUMENT.createElementNS(SVG_NS, 'svg');
  svgEl.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
  svgEl.setAttribute('xmlns:xlink', 'http://www.w3.org/1999/xlink');
  svgEl.setAttribute('version', '1.1');
  // Add <svg> element to SVG Document
  DOCUMENT.appendChild(svgEl);
  LOGGER.debug(`creating svg document ${DOCUMENT}`);</svg>
github cascornelissen / svg-spritemap-webpack-plugin / lib / style-formatters / scss.js View on Github external
view: ''
        },
        format: {
            type: 'data',
            publicPath: ''
        },
        variables: {
            sprites: 'sprites',
            variables: 'variables',
            sizes: 'sizes',
            mixin: 'sprite'
        }
    }, options);

    const XMLSerializer = new xmldom.XMLSerializer();
    const XMLDoc = new xmldom.DOMImplementation().createDocument(null, null, null);

    const output = symbols.reduce((accumulator, symbol) => {
        const svg = XMLDoc.createElement('svg');
        svg.setAttribute('xmlns', 'http://www.w3.org/2000/svg');
        svg.setAttribute('viewBox', symbol.getAttribute('viewBox'));

        // Clone symbol contents to svg
        Array.from(symbol.childNodes).forEach((childNode) => {
            if ( ['title'].includes(childNode.nodeName.toLowerCase()) ) {
                return;
            }

            svg.appendChild(childNode);
        });

        const sprite = XMLSerializer.serializeToString(svg);

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