Java [nodejs] вопрос

кис кис кис мяу гав

Новичок
Автор темы
4
0
Всем привет! Как вывести <ya:created dc:date="2020-09-26T07:51:39+03:00"/> в консоль?

1728591611814.png



Код:
var request = require('request');


var URL = 'https://vk.com/foaf.php?id=777111';


request(URL, function (err, res, body) {
    if (err) throw err;
    console.log(body);
    
    
  
    
});
 
Решение
JavaScript:
const request = require('request');
const xml2js = require('xml2js');

const parser = new xml2js.Parser();
const URL = `https://vk.com/foaf.php?id=410010808`;

request(URL, function (err, res, body) {
    if (err)
        throw err;
    console.log(`API Response: ${body}`);
    parser.parseString(body, function (err, result) {
        if (err)
            throw err;
        console.log(`Decoded: ${JSON.stringify(result)}`);
        const createdDate = result["rdf:RDF"]["foaf:Person"][0]["ya:created"][0]["$"]["dc:date"];
        console.log(`Created Date: ${createdDate}`);
    });
});

я котик

Участник
19
24
JavaScript:
const request = require('request');
const xml2js = require('xml2js');

const parser = new xml2js.Parser();
const URL = `https://vk.com/foaf.php?id=410010808`;

request(URL, function (err, res, body) {
    if (err)
        throw err;
    console.log(`API Response: ${body}`);
    parser.parseString(body, function (err, result) {
        if (err)
            throw err;
        console.log(`Decoded: ${JSON.stringify(result)}`);
        const createdDate = result["rdf:RDF"]["foaf:Person"][0]["ya:created"][0]["$"]["dc:date"];
        console.log(`Created Date: ${createdDate}`);
    });
});