IT Community - Software Programming, Web Development and Technical Support

Get XML node from string in Javascript

This is a discussion on Get XML node from string in Javascript within the PHP Programming forums, part of the Web Development category; hi, If i have a string in javascript say as var xmlstring = "<member><mem>a1&...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > PHP Programming

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 05-07-2007, 07:28 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Get XML node from string in Javascript

hi,
If i have a string in javascript say as
var xmlstring = "<member><mem>a1</mem><mem>a2</mem></member>"

i want to parse it to the xml node. In below i did for this.

<script language="Javscript">
var xmlstring = "<member><mem>a1</mem><mem>a2</mem></member>";
//# - convert a string to XML
var xmlRes =ffLoadXMLBrowser(xmlstring);
//# - get first node of mem value from the above string
alert(xmlRes.childNodes[0].getElementsByTagName( 'mem')[0].text)
function ffLoadXMLBrowser(strXML)
{
if(document.implementation && document.implementation.createDocument)
{
// MOZILLA or other Browser
xmlParser = new DOMParser();
xmlDocum = xmlParser.parseFromString( strXML, 'text/xml');
xmlSerializer = new XMLSerializer();


}
else if(window.ActiveXObject) {
// IE
xmlDocum = new ActiveXObject("Microsoft.XMLDOM");
xmlDocum.async=false;
xmlDocum.loadXML( strXML);
}
return xmlDocum;
}
</script>
__________________
With,
J. Jeyaseelan

Everything Possible
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Code-behind to create node dynamically using XML File or any Stored Procedure poornima ASP and ASP.NET Programming 3 02-14-2008 09:46 PM
Treeview control problem: Selected node is not retained when parent node is closed. bluesky ASP and ASP.NET Programming 1 01-23-2008 05:11 AM
Is it possible to Pass Query String to Javascript? velhari HTML, CSS and Javascript Coding Techniques 1 11-20-2007 10:47 PM
How can I search for a particular text string on the page?using javascript kingmaker HTML, CSS and Javascript Coding Techniques 2 08-14-2007 12:19 AM
How to change Tree Node Tree Node oxygen Flash Actionscript Programming 1 07-21-2007 02:51 AM


All times are GMT -7. The time now is 01:35 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0