How to use xml - 10 common examples

To help you get started, we’ve selected a few xml 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 TryGhost / gatsby-plugin-advanced-sitemap / src / IndexMapGenerator.js View on Github external
getXml(options) {
        const urlElements = this.generateSiteMapUrlElements(options)
        const data = {
            // Concat the elements to the _attr declaration
            sitemapindex: [XMLNS_DECLS].concat(urlElements),
        }

        // Return the xml
        return localUtils.getDeclarations(options) + xml(data)
    }
github TryGhost / gatsby-plugin-advanced-sitemap / src / BaseSiteMapGenerator.js View on Github external
// Using negative here to sort newest to oldest
                ts: -(self.nodeTimeLookup[id] || 0),
                node: node,
            }
        }, [])
        // Sort nodes by timestamp
        const sortedNodes = _.sortBy(timedNodes, `ts`)
        // Grab just the nodes
        const urlElements = _.map(sortedNodes, `node`)
        const data = {
            // Concat the elements to the _attr declaration
            urlset: [XMLNS_DECLS].concat(urlElements),
        }

        // Return the xml
        return localUtils.getDeclarations(options) + xml(data)
    }
github minio / minio-js / src / main / minio.js View on Github external
var query = `uploadId=${uriEscape(uploadId)}`

    var parts = []

    etags.forEach(element => {
      parts.push({
        Part: [{
          PartNumber: element.part
        }, {
          ETag: element.etag
        }]
      })
    })

    var payloadObject = {CompleteMultipartUpload: parts}
    var payload = Xml(payloadObject)

    this.makeRequest({method, bucketName, objectName, query}, payload, 200, '', true, (e, response) => {
      if (e) return cb(e)
      var transformer = transformers.getCompleteMultipartTransformer()
      pipesetup(response, transformer)
        .on('error', e => cb(e))
        .on('data', result => {
          if (result.errCode) {
            // Multipart Complete API returns an error XML after a 200 http status
            cb(new errors.S3Error(result.errMessage))
          } else {
            cb(null, result.etag)
          }
        })
    })
  }
github LinkedDataFragments / Client.js / lib / writers / SparqlXMLResultWriter.js View on Github external
SparqlXMLResultWriter.prototype._writeHead = function (variableNames) {
  // Write root element
  var self = this,
      root = this._root = xml.element({
        _attr: { xlmns: 'http://www.w3.org/2005/sparql-results#' },
      });
  xml({ sparql: root }, { stream: true, indent: '  ', declaration: true })
     .on('data', function (chunk) { self._push(chunk + '\n'); });

  // Write head element
  if (variableNames.length) {
    root.push({
      head: variableNames.map(function (v) {
        return { variable: { _attr: { name: v } } };
      }),
    });
  }
};
github LinkedDataFragments / Client.js / lib / writers / SparqlXMLResultWriter.js View on Github external
SparqlXMLResultWriter.prototype._flush = function (done) {
  // If there were no matches, the results element hasn't been created yet
  if (this._empty)
    this._root.push({ results: this._results = xml.element({}) });
  // There's no results element for ASK queries
  if (this._results)
    this._results.close();
  this._root.close();
  done();
};
github coreybutler / node-windows / lib / winsw.js View on Github external
{
      xml.push({
        serviceaccount: [
          {domain: config.logOnAs.domain},
          {user: config.logOnAs.account},
          {password: config.logOnAs.password}
        ]
      });
    }

    // if no working directory specified, use current working directory
    // that this process was launched with
    xml.push({workingdirectory: config.workingdirectory || process.cwd()});

    // indent resultant xml with tabs, and use windows newlines for extra readability
    return require('xml')({service:xml}, {indent: '\t'}).replace(/\n/g,'\r\n');
  },
github DefinitelyTyped / DefinitelyTyped / xml / xml-tests.ts View on Github external
test('streams end properly', t => {
    const elem = xml.element({ _attr: { decade: '80s', locale: 'US'} });
    const xmlStream = xml({ toys: elem }, { stream: true });

    let gotData = false;

    t.plan(7);

    elem.push({ toy: 'Transformers' });
    elem.push({ toy: 'GI Joe' });
    elem.push({ toy: [{name: 'He-man'}] });
    elem.close();

    xmlStream.on('data',  (data: any) => {
        t.ok(data);
        gotData = true;
    });
github DefinitelyTyped / DefinitelyTyped / types / xml / xml-tests.ts View on Github external
test('streams end properly', t => {
    const elem = xml.element({ _attr: { decade: '80s', locale: 'US'} });
    const xmlStream = xml({ toys: elem }, { stream: true });

    let gotData = false;

    t.plan(7);

    elem.push({ toy: 'Transformers' });
    elem.push({ toy: 'GI Joe' });
    elem.push({ toy: [{name: 'He-man'}] });
    elem.close();

    xmlStream.on('data',  (data: any) => {
        t.ok(data);
        gotData = true;
    });
github fibjs / fibjs / test / xml_suite.js View on Github external
it("xml_files/xml/" + id + ".xml", () => {
            var txt = fs.readTextFile(path.join(__dirname, "xml_files", "xml", id + ".xml"));
            var json = fs.readTextFile(path.join(__dirname, "xml_files", "json", id + ".json"));
            var out = fs.readTextFile(path.join(__dirname, "xml_files", "out", id + ".xml"));

            var xdoc = xml.parse(txt);
            assert.equal(JSON.stringify(dump_dom(xdoc)), json);
            assert.equal(xdoc.toString(), out);

            var xdoc1 = xdoc.cloneNode();
            assert.notEqual(xdoc, xdoc1);
            assert.equal(JSON.stringify(dump_dom(xdoc1)), json);
            assert.equal(xdoc1.toString(), out);

            xdoc1.normalize();
            assert.equal(xdoc1.toString(), out);
            assert.equal(JSON.stringify(dump_dom(xdoc1)), json);
        });
    }
github geoadmin / mf-geoadmin3 / scripts / create_sitemaps.js View on Github external
file.on('open', function(fd) {
    var indexRoot = xml.element({ _attr: {xmlns: 'http://www.sitemaps.org/schemas/sitemap/0.9'}});
    var xmlstream = xml({ sitemapindex: indexRoot}, { stream: true, indent: '  ', declaration: {encoding: 'UTF-8'}});
    xmlstream.on('data', function (chunk) {
      file.write(chunk + '\n');
      if (chunk == endMarker) {
        file.write('\n');
      }
    });

    results.forEach(function(res) {
      if (res.value.result) {
        indexRoot.push({ sitemap: [{ loc: HOSTNAME + '/sitemap_' + res.value.origin.name + '.xml'}] });
      } else {
        console.log('An Error occured during the creation of the ' +  res.value.origin.name + ' sitemap. ------> SKIPPED!');
      }
    });