File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes XML and Related Technologies and the fly likes Parsing XML in Javascript Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "Parsing XML in Javascript" Watch "Parsing XML in Javascript" New topic

Parsing XML in Javascript

Shreya Menon
Ranch Hand

Joined: Jul 31, 2001
Posts: 285
I do have a Javascript variable which holds an XML string.
var replyXML = <Name>
I want to extract the values of First and Last and Save it into two Javascript variables.
How to do that ?
I have heard that using DHTML this can be done .. Any help

Can we use parser in Javascript ? If so which is the best parser to use ?

[This message has been edited by maya menon (edited August 21, 2001).]
David Weitzman
Ranch Hand

Joined: Jul 27, 2001
Posts: 1365
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Transforming XML to HTML on the client
Here is the simple source code needed to transform the XML file to HTML on the client (try it yourself):
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
// Transform

The first block of code creates an instance of the Microsoft XML parser (XMLDOM), and loads the XML document into memory. The second block of code creates another instance of the parser and loads the XSL document into memory. The last line of code transforms the XML document using the XSL document, and writes the result to the HTML document.
Tom George
Ranch Hand

Joined: Jan 28, 2004
Posts: 41
Seems the code you've posted will work only with IE. I'm looking for javascript syntax that can parse xml, across browsers. Is that a mirage??
William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Amazing what you can find with a Google search - for example
this cross browser javascript parser project on sourceforge.
I agree. Here's the link:
subject: Parsing XML in Javascript
It's not a secret anymore!