For the past two weeks, much of my work on the ownCloud photo upload app has been centered around serializing, parsing, receiving, and sending XML. While most web APIs I've encountered use JSON to communicate nuanced data, XML is WebDAV's core mode of data communication, and there was really no getting around using it for this project. (I've written before about understanding WebDAV.)

I decided to approach the parts of my project that dealt with XML through test-driven development, due to XML and WebDAV each having very specific expectations about format.

The most important connection I made while working with XML in the browser was this: your browser is a markup-parsing machine.

Before I used JavaScript for my OPW internship, most of my JS experience came from building server-side Node.js applications. Through working with Node, I had become accustomed to having to install supplemental NPM modules to take care of various parsing and formatting tasks.

The great thing about building web apps is that many of these utility functions are actually built in (unless you are using IE9 or earlier, in which case some of them built in). You do not need to write your own base64 encoding methods, because those are in your browser. And you certainly don't need to import a library to start parsing XML, because your browser already has a pretty good idea of how to do that. HTML, the markup language of the web, is a standard markup language. Your browser's main job is to chew up markup and spit out views. It would be a little unfair if we weren't able to cash in on this functionality directly!

All it takes to convert an ugly string like '<D:propfind xmlns:D="DAV:"><D:allprop/></D:propfind>' into a document object that I can inspect and expand in my browser console is a new DOMParser(); and its parseFromString() method. MDN's documentation for this process explains this in detail. This was a really helpful tool when trying to make sense of longer XML responses returned by requests to ownCloud's WebDAV server.

This isn't to say that you won't ever need external libraries for these sort of things. You might! But until working closely with the document object and its related interfaces, I didn't realize the breadth of tools available to me.