tags:

views:

338

answers:

3

Hello,

I'm diving into javascript and one of the concepts I'm playing with is XML parsing. I see that IE has its own parser, as does Firefox. I also see XML parsers built into some of the javascript frameworks like JQuery. My questions are...

  1. What's the most common or best way to parse XML using javascript these days?
  2. If I use the built-in MS and Firefox parsers, does that mean my code is only guaranteed to work in IE and Firefox, or will the other popular browsers work as well?

Thanks in advance for all your wisdom!

EDIT* I just found this discussion, looks very similar to my question..

+1  A: 

The DOMParser interface exists in every major browser, and has many benefits over js implementations -- speed and correctness are the big ones.

olliej
+1  A: 

What's the most common or best way to parse XML using javascript these days?

I would use a framework parser to avoid writing code depending on the browser.

If I use the built-in MS and Firefox parsers, does that mean my code is only guaranteed to work in IE and Firefox, or will the other popular browsers work as well?

Each browser has its own way of loading and manipulating XML.

For eg:

IE uses an ActiveX object to load XML whereas firefox doesn't.

rahul
A: 

Sarissa is a JS library that helps abstract away some of the differences between browsers XML API calls.

Sarissa is an ECMAScript library acting as a cross-browser wrapper for native XML APIs. It offers various XML related goodies like Document instantiation, XML loading from URLs or strings, XSLT transformations, XPath queries etc and comes especially handy for people doing what is lately known as "AJAX" development.

Supported browsers are Mozilla - Firefox and family, Internet Explorer with MSXML3.0 and up, Konqueror (KDE 3.3+ for sure), Safari and Opera. Konq and Safari offer no XSLT/XPath scripting support AFAIK.

Mads Hansen