Solved

jquery of javascript parse xml

Posted on 2013-05-17
2
539 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
advertisement module in core php 4 89
gif overlay 3 32
Bypass cross origin issues on development site 3 22
Website Redirection 8 16
PROBLEM: The other day I was working on adding an ajax request to a webpage that already had a dialog box on the page.  The dialog box was using relative positioning to be positioned next to a form field I had on the page.  Everything was working…
Many times as a report developer I've been asked to display normalized data such as three rows with values Jack, Joe, and Bob as a single comma-separated string such as 'Jack, Joe, Bob', and vice versa.  Here's how to do it. 
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now