PHP's SimpleXMLElement analog for Node.js

The best XML reading and writing API I've ever used is PHP's SimpleXMLElement. For example, to create a DOM of the following XML text:

<root>
    <foo>
        <bar baz="goo">
            moo
        </bar>
    </foo>
</root>

in PHP one would just write:

$root = new SimpleXMLElement('<root/>');
$root->foo->bar = 'moo';
$root->foo->bar['baz'] = 'goo';

Same style for reading XML, with addition of xpath() function.

I heard people calling it a "builder pattern". Not quite sure if that's appropriate. Anyway, is there any API under Node.js having a comparable ease of use?

Yep, it has jsdom.

jsdom allows you to use the DOM as if you were on the client.

You can even use jQuery with it if bare DOM scares you.

Example from doc:

// Run some jQuery on a html fragment
var jsdom = require('jsdom');

jsdom.env('<p><a class="the-link" href="https://github.com/tmpvar/jsdom">jsdom\'s Homepage</a></p>', [
  'http://code.jquery.com/jquery-1.5.min.js'
],
function(errors, window) {
  console.log("contents of a.the-link:", window.$("a.the-link").text());
});