Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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)
}
// 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)
}
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)
}
})
})
}
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 } } };
}),
});
}
};
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();
};
{
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');
},
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;
});
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;
});
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);
});
}
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!');
}
});