suitability for XML documents

65 views
Skip to first unread message

Jake

unread,
Jun 5, 2011, 1:01:23 AM6/5/11
to jsdom
Hi,

I'm wondering if jsdom can be used to parse and manipulate XML
documents using the W3C XML DOM API? I've read through the
documentation on github, and it seems that the project is primarily
focused on emulating the browser environment, as opposed to providing
a standards-compliant XML parser. However, I saw that under the tests
for W3C compliance, it stated that jsdom was 100% compliant for DOM
Level 1 html/svg/xml. In the short tests I've performed with the
module downloaded via npm, jsdom seemed to be able to parse the XML
documents I gave it, but some calls seemed to conform to HTML DOM, as
opposed to XML DOM. For example element.tagName would return the tag
name in uppercase, as opposed to returning the case-sensitive version.
I didn't try working with namespaces.

I'd appreciate hearing people's opinions regarding whether jsdom
suitable for working with XML documents. Thanks,

Jake

Jake B

unread,
Jun 5, 2011, 10:57:59 AM6/5/11
to jsdom
Hi,

I've read through the documentation, and some of the source code of
jsdom.js, and it seems like it should be possible to use jsdom to
parse an XML document so that it can be manipulated with the DOM Level
2 Core API. I've followed the instructions in this code snippet in the
README:


level is null (which means level3) by default, but you can pass
another level if you'd like.

var jsdom = require('jsdom'),
doc = jsdom.jsdom('<html><body></body></html>', jsdom.dom.level1.core)


jsdom.dom.level1 is actually not exposed on jsdom.dom (it seems that
only level 3 is), but I was able to reference it by passing the full
path to the module. Unfortunately, the results were the same: in the
resulting document, doc.documentElement was none, the element that
should have been the documentElement was the first child, and tagName
returned the tag's name in normalized uppercase.

I then dove into the source of jsdom, and found the following code snippets


var dom = exports.dom = require("./jsdom/level3/index").dom,
...
exports.defaultLevel = dom.level3.html;

I tried changing these to:


var dom = exports.dom = require("./jsdom/level2/index").dom,
...
exports.defaultLevel = dom.level2.core;


With the intention that it would use core XML DOM, as opposed to HTML
DOM, but the results were the same as above.

I'm not sure where I'm going wrong, or what else to try. It seems like
what I'm attempting should be possible, and I also seem to be
following the documentation, but it doesn't seem to be working. I'd
appreciate any guidance anyone can offer into this. Thanks,

Jake

Reply all
Reply to author
Forward
0 new messages