I'm attempting to scan an XML file for a specific "attribute". This is the file: The image
I'd like to parse it for the "file_url" attribute, but I have no clue to how.
If anyone can help me, It'd be very much appreciated.
You can use node xml2js module for parsing
Code is as follows:-
var parseString = require('xml2js').parseString;
var xml = "<root>Hello xml2js!</root>"
parseString(xml, function (err, result) {
// you can access file url as given below
console.dir(result.file_url);
});
Xml is converted into javascript object so you can access each attributes just like object properties of js.
Related
Is there any way to convert res object in nodejs to JSON object
app.post('/validateUser', function (req, res)
{
console.log('in post validateUser');
var usr = req.body.usr;
var pwd = req.body.pwd;
//like this
callSomeFunctionOrWebservice(JSON.stringify({data:req.body, respVar:res}));
// the above function gave me error //TypeError: Converting circular structure to JSON at
});
what I need is to convert the entire thing to JSON, pass the arguments and retrieve the arguments on the other function maybe call a web service
I checked out flatted, but I don't know how to encode with flatted
I tried this
var flt = require('flatted');
//JSON encrypt
flt.stringify({data:req.body, respVar:res});
//JSON parse
flt.parse(varData);
But I couldn't get it to work. Can someone helps me or point me in the correct direction?
You no need convert res to json it is already in json object only.
So
var new_object = {data:req.body, respVar:res}
or if you want combine both
var new_object = {...req.body,...res}
console.log(new_object)
Check that it can accessible like json only
As the question states, is there a way to use mammoth so that it doesn’t require writing to disk? I see the following package:
https://www.npmjs.com/package/mammoth
var mammoth = require("mammoth");
mammoth.convertToHtml({path: "path/to/document.docx"})
.then(function(result){
var html = result.value; // The generated HTML
var messages = result.messages; // Any messages, such as warnings during conversion
})
.done();
In the mammoth document, the first parameter of convertToHtml function is input, with input is an object describing the source document. On node.js, they supported {path: path} and {buffer: buffer} (or {arrayBuffer: arrayBuffer}).
You can convert the uploaded file to a buffer then push the buffer to convertToHtml function.
I am using Highcharts Node.js Export Server module in my nodejs application.
I want to get the response as SVG string rather than generating the SVG file on the server.
Is it possible to get the SVG String as response.
I am using the latest Highcharts Node.js Export Server module .
I can get the base64 encoded data in res.data but i cannot see any ways to get the SVG string as response.
I am using below snippet to call the exporter module :
exporter.initPool();
exporter.export(exportSettings, function (err, res) {
exporter.killPool();
process.exit(1);
});
I want to get the response as SVG string like
" ........"
Unfortunately, it is not possible to get a response as an SVG string instead of the file. However, it can be achieved by reading the file returned by the export callback. Optionally after this operation, the file can be removed.
Code:
exporter.export(exportSettings, function(err, res) {
if (res.filename) {
let svgString = fs.readFileSync(res.filename, 'utf8');
console.log(svgString);
// Remove the file optionally
fs.unlinkSync(res.filename);
}
exporter.killPool();
process.exit(1);
});
The parse module in querystring lib lists the following.
querystring.parse(str[, sep[, eq[, options]]])
I've also seen the following code
const { parse } = require('querystring')
...
let actual = parse(queryString)[queryStringPropName]
Why is the array appended after parse(queryString) and more importantly, why does it work?
The array-appending was not seen in querystring's API page in NodeJS.
Can anyone explain?
That's because parse(queryString) is an object and in this case, [queryStringPropName] is not an array, it is to access a prop of the object parse(queryString)
I'm having some issues trying to request an image file from Cloud Clode in Parse.
This is my Parse Cloud Code:
Parse.Cloud.define("datata", function(request, response) {
//var message = request.params.message;
var file = request.params.file;
//console.log(file);
var base64 = file.toString("base64");
var data = new Parse.File("test.jpg", {
base64: base64
});
data.save().then(function() {
// The file has been saved to Parse.
console.log("WIN");
}, function(error) {
console.log("LOSE");
// The file either could not be read, or could not be saved to Parse.
});
});
The problem is when I try to post the file I got this as an answer from the server:
{"code":107,"error":"invalid utf-8 string was provided"}
I'm trying to create custom endpoints for some custom hooks, that why I'm working with Cloud Code.
Anyone have any idea about how can I create and endpoint in Parse Cloud Code for requesting and creating files?
Thanks in advance.
What JSON response did you get when you POST'd the file?
You need to use the "url" value in order to GET the file.
{"__type":"File","name":"e580f231-90ba-4d24-934c-7f9e7c8652d6-picf1","url":"http://files.parse.com/1315e4d8-f302-4337-adbe-d8650ab5c312/e580f231-90ba-4d24-934c-7f9e7c8652d6-picf1"}
So, in the example above which is very similar to the response when a file type is POST'd, you would use the value of the "url" tag in a http/GET.