Solved

jquery of javascript parse xml

Posted on 2013-05-17
2
543 Views
Last Modified: 2013-05-17
Hi,
I have a webservice response that comes back as xml text.  Can someone please tell me how to make a function (or statment) that can get

session-id out of this string?

<?xml version="1.0"?><amtd><result>OK</result><xml-log-in><session-id>83D7D6CB23366AE5BF6D2846000FD71F.5krocvxvOyOCZsGalRLdzQ</session-id><user-id>xxxxxx</user-id><cdi>dddddd</cdi><timeout>55</timeout><login-time>2013-05-17 16:05:55 EDT</login-time><associated-account-id>xxxxxx</associated-account-id><nyse-quotes>realtime</nyse-quotes><nasdaq-quotes>realtime</nasdaq-quotes><opra-quotes>realtime</opra-quotes><amex-quotes>realtime</amex-quotes><cme-quotes>delayed</cme-quotes><ice-quotes>delayed</ice-quotes><forex-quotes>delayed</forex-quotes><exchange-status>non-professional</exchange-status><authorizations><options360>false</options360></authorizations><accounts><account><account-id>xxxxxx</account-id><display-name>xxxxxx</display-name><cdi>dddddddd</cdi><description>xxxx MILLMAN</description><associated-account>true</associated-account><company>AMER</company><segment>ADVNCED</segment><unified>true</unified><preferences><express-trading>false</express-trading><option-direct-routing>false</option-direct-routing><stock-direct-routing>false</stock-direct-routing></preferences><authorizations><apex>true</apex><level2>true</level2><stock-trading>true</stock-trading><margin-trading>true</margin-trading><streaming-news>true</streaming-news><option-trading>full</option-trading><streamer>true</streamer><advanced-margin>true</advanced-margin></authorizations></account><account><account-id>ddddd</account-id><display-name>xxxxxxroth</display-name><cdi>ddddd</cdi><description>xxx TD</description><associated-account>false</associated-account><company>AMER</company><segment>ADVNCED</segment><unified>true</unified><preferences><express-trading>false</express-trading><option-direct-routing>false</option-direct-routing><stock-direct-routing>false</stock-direct-routing></preferences><authorizations><apex>true</apex><level2>true</level2><stock-trading>true</stock-trading><margin-trading>true</margin-trading><streaming-news>true</streaming-news><option-trading>spread</option-trading><streamer>true</streamer><advanced-margin>true</advanced-margin></authorizations></account><account><account-id>dddddddd</account-id><display-name>xxxxxxira</display-name><cdi>dddddd</cdi><description>xxxxxx IRA</description><associated-account>false</associated-account><company>AMER</company><segment>ADVNCED</segment><unified>true</unified><preferences><express-trading>false</express-trading><option-direct-routing>false</option-direct-routing><stock-direct-routing>false</stock-direct-routing></preferences><authorizations><apex>true</apex><level2>true</level2><stock-trading>true</stock-trading><margin-trading>true</margin-trading><streaming-news>true</streaming-news><option-trading>spread</option-trading><streamer>true</streamer><advanced-margin>true</advanced-margin></authorizations></account></accounts></xml-log-in></amtd>
0
Comment
Question by:jackjohnson44
2 Comments
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 39176125
test page : http://jsfiddle.net/YYT6J/2/
Using : http://api.jquery.com/jQuery.parseXML/
var xml= "<?xml version=\"1.0\"?><amtd><result>OK</result><xml-log-in><session-id>83D7D6CB23366AE5BF6D2846000FD71F.5krocvxvOyOCZsGalRLdzQ</session-id><user-id>xxxxxx</user-id><cdi>dddddd</cdi><timeout>55</timeout><login-time>2013-05-17 16:05:55 EDT</login-time><associated-account-id>xxxxxx</associated-account-id><nyse-quotes>realtime</nyse-quotes><nasdaq-quotes>realtime</nasdaq-quotes><opra-quotes>realtime</opra-quotes><amex-quotes>realtime</amex-quotes><cme-quotes>delayed</cme-quotes><ice-quotes>delayed</ice-quotes><forex-quotes>delayed</forex-quotes><exchange-status>non-professional</exchange-status><authorizations><options360>false</options360></authorizations><accounts><account><account-id>xxxxxx</account-id><display-name>xxxxxx</display-name><cdi>dddddddd</cdi><description>xxxx MILLMAN</description><associated-account>true</associated-account><company>AMER</company><segment>ADVNCED</segment><unified>true</unified><preferences><express-trading>false</express-trading><option-direct-routing>false</option-direct-routing><stock-direct-routing>false</stock-direct-routing></preferences><authorizations><apex>true</apex><level2>true</level2><stock-trading>true</stock-trading><margin-trading>true</margin-trading><streaming-news>true</streaming-news><option-trading>full</option-trading><streamer>true</streamer><advanced-margin>true</advanced-margin></authorizations></account><account><account-id>ddddd</account-id><display-name>xxxxxxroth</display-name><cdi>ddddd</cdi><description>xxx TD</description><associated-account>false</associated-account><company>AMER</company><segment>ADVNCED</segment><unified>true</unified><preferences><express-trading>false</express-trading><option-direct-routing>false</option-direct-routing><stock-direct-routing>false</stock-direct-routing></preferences><authorizations><apex>true</apex><level2>true</level2><stock-trading>true</stock-trading><margin-trading>true</margin-trading><streaming-news>true</streaming-news><option-trading>spread</option-trading><streamer>true</streamer><advanced-margin>true</advanced-margin></authorizations></account><account><account-id>dddddddd</account-id><display-name>xxxxxxira</display-name><cdi>dddddd</cdi><description>xxxxxx IRA</description><associated-account>false</associated-account><company>AMER</company><segment>ADVNCED</segment><unified>true</unified><preferences><express-trading>false</express-trading><option-direct-routing>false</option-direct-routing><stock-direct-routing>false</stock-direct-routing></preferences><authorizations><apex>true</apex><level2>true</level2><stock-trading>true</stock-trading><margin-trading>true</margin-trading><streaming-news>true</streaming-news><option-trading>spread</option-trading><streamer>true</streamer><advanced-margin>true</advanced-margin></authorizations></account></accounts></xml-log-in></amtd>";

// http://api.jquery.com/jQuery.parseXML/
xmlDoc = $.parseXML( xml );
$xml = $( xmlDoc );
$sessionId = $xml.find("session-id");

Open in new window

0
 

Author Comment

by:jackjohnson44
ID: 39176126
jQuery is the best!!!
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question