File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
Author

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>
<First>Maya</First>
<Last>Menon</Last>
</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 ?
Thanks,
Maya


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

Joined: Jul 27, 2001
Posts: 1365
http://home.worldcom.ch/~jmlugrin/fesi/xparse.txt
Sham Jowsaki
Ranch Hand

Joined: May 22, 2001
Posts: 146
Hi
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):
<html>
<body>
<script language="javascript">
// Load XML
var xml = new ActiveXObject("Microsoft.XMLDOM")
xml.async = false
xml.load("cd_catalog.xml")
// Load the XSL
var xsl = new ActiveXObject("Microsoft.XMLDOM")
xsl.async = false
xsl.load("cd_catalog.xsl")
// Transform
document.write(xml.transformNode(xsl))
</script>
</body>
</html>

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.
Cheers
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
Rancher

Joined: Mar 22, 2000
Posts: 12791
    
    5
Amazing what you can find with a Google search - for example
this cross browser javascript parser project on sourceforge.
Bill
 
 
subject: Parsing XML in Javascript