Open XML file in AppleScript with JavaScript syntax - javascript

I am writing my first bigger AppleScript and as I am usually developing TypeScript, I decided to use the JavaScript version of AppleScript. I need to read and parse an XML file.
Apple has an Example for that on their documentation, however the documentation only has an example in the AppleScript syntax, not in the JavaScript syntax:
https://developer.apple.com/library/archive/documentation/LanguagesUtilities/Conceptual/MacAutomationScriptingGuide/WorkwithXML.html#//apple_ref/doc/uid/TP40016239-CH67-SW1
How do I actually do the given example in JavaScript?
I can read the file as a String, but that does not help me as I need to traverse the XML-tree.

In the end I used webpack and an npm-package for parsing XML files to JSON: https://www.npmjs.com/package/fast-xml-parser
my code example is here:
https://github.com/kellertobias/rekordbox-to-music-playlists/blob/master/src/load-rekordbox.ts

Related

How can I interpret config documentation examples written in JSON or JavaScript and know how it would translate to YAML?

For example, the puppeteer config documentation has an example of a configuration file written in JavaScript. There aren't any examples of how to use a YAML file instead. For the sake of conformity, I would like to have all configuration files in my project written in one language. I can convert a JavaSript config to JSON and vice versa without needing documentation, can the same be done with YAML?
I just needed this resource on syntax conversion: https://www.json2yaml.com/

Turn CSV file into array using Vanilla Javascript without input element

I am trying to read turn a CSV file, the file is on local, could be same folder with the script file. Since I am writing JSX for photoshop, I couldn't use any other library. And there are a lot of tutorial out there using input element which is not what I need. The path of the file could be hard coded. What I am trying to do is read the CSV, and take out some data. Please advise!
Let me explain it clearly!
I am writing JSX for photoshop script which has no browser element - input tag something like that. And it must be pure Javascript no library such as jQuery. I did a lot of google search what they do is taking the input tag from browser let user select the CSV file, I just want the file path is hard code, it is a fixed path and filename. And I don't see any tutorial for read CSV file and turn into array via vanilla javascript.
You can use the File class. How this works is explained in the ExtendScript toolkit docs which are installed on your computer alongside Creative Cloud. An online version can also be found here. (The scripting guide references this under the File object on page 110, referring to a section about JavaScript on different platforms on page 32, which then refers to the ExtendScript docs.)
Example:
const file = new File("/c/Users/user/Desktop/text.csv");
file.encoding = 'UTF-8';
file.open("r");
const contents = file.read();
file.close();
alert(contents);

intellij idea UNDERSCOREJS / EJS formatter

I registered *.tpl file type as a "Java Server Page" file, although it's an UnderscoreJS template code (JavaScript! Not Java as the file editor points, due to this configuration).
It's all nice but the formatting breaks the code lines of my EJS style template code, as shown in the following image:
I've managed to isolate the problem - it breaks when my code uses Underscore.JS' each() function, i.e code like the following creates the breaking (otherwise it would format nicely):
_.each(models, function(model) {
// some code..
}
);
What can be done? I'm looking for a "native" solution, i.e not use Eclipse formatting plugin.
Maybe associate the file type with another editor? Then, which?
There's an EJS plugin in IDEA 13.

Does parsing an uploaded JSON with ActiveRecord::Serialization.from_json() in RoR open up any security loophole?

I am planning on implementing an export-import functionality in Ruby on Rails.
Now since JSON can include JavaScript, I wonder if anyone could inject malicious code that can be run when I ask ruby to convert the JSON to a hash.
No, JSON can not include javascript code*. It is more strict version of Javascript object literal synthax.
http://json.org/
*- actually, javascript code could be included in JSON in string, but it won't be parsed.

Javascript XML parsing or alternative

I'm building a Javascript preview function for a blog back-end (much like the one used on this website), and I'd like to be able to parse some custom tags that normally get parsed by PHP. I am wondering if it's possible to use the JS XML parser to parse content from a textarea that would look like:
<img=1>
Use for
<url=http://apwit.com>testing</url>
purposes only!
I read on another question here once that using regex to parse things like this is a bad idea because of the many many exceptions there could be. What do you think?
Use this: http://www.w3schools.com/Xml/tryit.asp?filename=tryxml_parsertest2
It parses xml from a string and uses the fast native XML parsing engine from the browser.
Explanation and discussion:
http://www.w3schools.com/Xml/xml_parser.asp

Categories