Every once in a while I use up a Friday night and Saturday to learn a little something new and whip up a quick project. My most recent project involved the File API and a little bit of XML reading.
In the case of this project, I've actually already worked on something very similar a few months ago, which was a project I had started to learn about Atom Shell. However, Atom Shell is meant for a local type installation and I wanted to see how far the browser was capable of going by itself.
After my initial confusion of the unsupported Filesystem API with the actual, current File API, I was able to basically copy the example code from HTML5Rocks and change it up to take in the XML files that I would select via the File dialog.
The first issue arises where, apparently, I can't use the input[type=file] to choose a directory. Chrome seems to have some initial support but I usually don't bother with features - even really new stuff - until both Chrome AND Firefox (my main browser) support it. So that's a bummer, and I'll have to wait on that to ever have a "completed" version of this "app", but for now throwing the
multiple attribute is enough.
The second issue was reading XML. I figured it'd be a little easier than it was, probably because with Atom Shell the node-xml2js package made that easy peezy, however without node I had a little more trouble. After some fiddling I was able to print the XML in
console.log, albeit in base 64. I tried using 2 libraries, xmldoc and Dom2JSON to try and convert the XML straight into a JSON object or something, but they weren't working very well for me (or I just couldn't figure them out). I ended up using the built-in DOMParser and was able to get an object I could actually go through in the developer tools.
Finally, although quite un elegantly, I was able to iterate through some known areas in the object to spit out into a table and basically list a couple specific values in a couple of columns for me. For me to mark this off as a "completed" project, I'll need a few things:
Ability to choose a folder and grab XML's from specific subdirectories in one go
A smoother recursion of the data, so that I can add/remove columns easily in the future
Implement some sort of columning sorting or filtering
But, that'll happen some other weekend.