How to use the xml.element function in xml

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 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 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 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!');
      }
    });
github smontanari / code-forensics / lib / vcs / svn / svnlog_stream_transformer.js View on Github external
this.normaliseLogStream = function(inputStream, pathEvalCallback) {
    var logEntryScanner = new LogEntryScanner(_.partialRight(transformNodeChildren, pathEvalCallback));
    var rootElement = xml.element();
    var outputStream = xml({ log: rootElement }, { declaration: true });
    var reader = XmlReader.create({ stream: true });

    reader.on('tag:logentry', function(node) {
      var logentryElement = logEntryScanner.scan(node);
      if (logentryElement !== null) {
        rootElement.push(logentryElement);
      }
    });
    inputStream
      .on('data', function(chunk) { reader.parse(decoder.write(chunk)); })
      .on('end', function() { rootElement.close(); });

    return outputStream;
  };
};
github Callidon / sparql-engine / src / formatters / xml-formatter.js View on Github external
constructor (source, variables, options) {
    super(source, variables, options)
    this._root = xml.element({
      _attr: { xmlns: 'http://www.w3.org/2005/sparql-results#' }
    })
    this._results = xml.element({})
    this._stream = xml({ sparql: this._root }, { stream: true, indent: '\t', declaration: true })
    this._stream.on('data', v => this._push(v))
  }
github Callidon / sparql-engine / src / formatters / xml-formatter.js View on Github external
constructor (source, variables, options) {
    super(source, variables, options)
    this._root = xml.element({
      _attr: { xmlns: 'http://www.w3.org/2005/sparql-results#' }
    })
    this._results = xml.element({})
    this._stream = xml({ sparql: this._root }, { stream: true, indent: '\t', declaration: true })
    this._stream.on('data', v => this._push(v))
  }