How to use the select1 function from xpath

Find comprehensive JavaScript xpath.select1 code examples handpicked from public code repositorys.

3
4
5
6
7
8
9
10
11
12


app.get('/some/route', function(req, res) {
  let tainted = req.param("userName");
  xpath.parse(tainted); // NOT OK
  xpath.select(tainted); // NOT OK
  xpath.select1(tainted); // NOT OK
  let expr = xpath.useNamespaces(map);
  expr(tainted); // NOT OK
});
fork icon0
star icon2
watch icon0

57
58
59
60
61
62
63
64
65
66
67
68
69
async function main() {
	const data = USE_LOCAL_DATA ? getLocalData() : await getExternalData()


	const xml = domparser.parseFromString(data)


	const table = xpath.select1('//table', xml)


	if (!table) {
		console.error('No table found in the HTML response...')
		process.exit(1)
fork icon0
star icon14
watch icon6

+ 10 other calls in file

23
24
25
26
27
28
29
30
31
32
const doc = new dom({ errorHandler: {
	warning: w => {},
	error: e => {},
	fatalError: e => { console.error(e) },
}}).parseFromString(html);
const page = xpath.select1("//span[contains(@class, 'normal')]", doc);

const gameInfo = xpath.select1("./following::h2[normalize-space(text()) = 'Game info']/following-sibling::p", page);
const game = options.game || xpath.select1("normalize-space(./big[normalize-space(text()) = 'Name:']/following-sibling::a/text())", gameInfo);
const developersStart = xpath.select1("./big[normalize-space(text()) = 'Developers:' or normalize-space(text()) = 'Developer:']", gameInfo);
fork icon0
star icon0
watch icon0

+ 29 other calls in file

10
11
12
13
14
15
16
17
18
19
20
const PLATFORM_MAP = { 'DOS': 'PC' };


async function fetchGame({ url, composer, song_pattern, song_count, song_ignore, rate, samples }, source, options) {
	const html = await (await fetch(url)).text();
	const doc = new dom().parseFromString(html);
	const infoTable = xpath.select1('//div[@id="mw-content-text"]/table[1]', doc);
	const game = options.game || xpath.select('normalize-space(./tr[1]/td)', infoTable);
	const metricsTable = xpath.select1('.//table', infoTable);
	const platformStr = xpath.select('normalize-space(./tr[normalize-space(./td[1]) = "Platform:"]/td[2])', metricsTable);
	const platform = PLATFORM_MAP[platformStr] || platformStr;
fork icon0
star icon0
watch icon0

+ 13 other calls in file

39
40
41
42
43
44
45
46
47
48
if (GAME_DUPLICATES.includes(url))
	return null;

const html = await (await fetch(url)).text();
const doc = new dom().parseFromString(html);
const infobox = xpath.select1("//table[contains(@class, 'infobox')]", doc);
const title = normalizeName(xpath.select("normalize-space(.//tr[1]/th/i)", infobox));
//const composers = xpath.select(".//tr[normalize-space(th/text()) = 'Composer(s)']/td/a/text()", infobox).map(t => t.data);
const developers = xpath.select(".//tr[normalize-space(th/text()) = 'Team(s)']/td/a/text()", infobox).map(t => t.data);
const publishers = xpath.select(".//tr[normalize-space(th/text()) = 'Publisher(s)']/td/a/text()", infobox).map(t => t.data);
fork icon0
star icon0
watch icon0

+ 3 other calls in file

18
19
20
21
22
23
24
25
26
27
do {
  page = page + 1;
  const res = syncRequest('GET', pidUrl(page));
  const xml = res.getBody('utf8');
  const doc = new dom().parseFromString(xml);
  remainder = xpath.select1('/programmeList/remainder', doc).firstChild.data;
  const links = xpath.select('//link', doc);
  const titles = xpath.select('//title', doc);
  for (let i=0; i < links.length; i++) {
    const pid = /(\d\d*)/.exec(links[i].firstChild.data)[1];
fork icon0
star icon0
watch icon0

54
55
56
57
58
59
60
61
62
63
do {
  p = p + 1;
  const res = syncRequest('GET', episodesUrl(Pid, year, p));
  const xml = res.getBody('utf8');
  const doc = new dom().parseFromString(xml);
  remainder = xpath.select1('/episodeList/remainder', doc).firstChild.data;
  const dates = xpath.select('//episodeDate', doc);
  const titleCaptions = xpath.select('//episodeTitle', doc);
  const audios = xpath.select('//mediafile', doc);
  for (let i = 0; i < titleCaptions.length; i++) {
fork icon0
star icon0
watch icon0