tags:

views:

653

answers:

2

I am using jQuery to grab results from a webservice(3rd party can't change). A result set is something like:

<result> 
 <contactId>1234</contactId> 
 <contactState>9</contactState> 
 <contactStateSortOrder>5</contactStateSortOrder>
  <address>
    <addressId>568</addressId> 
    <contactId>9801</contactId> 
  </address>
</result>

Now I am using

$('result', xml).each(function() {
   $("contactId", this).text();
  });

to get the contact id out and doing what i need to do however the end result is 12349801 all i would like is the 1234. Any ideas?

Thanks in advvace

+2  A: 

Change your selector. To get 1234 in your example, use result > contactId; to get 9801 use address > contactId

You could also do contactId:not(adress > contactId)

geowa4
Thank you, worked with > contactID :)
Si Philp
@Si Philip: no problem
geowa4
A: 

Either this:

$('result > contactId', xml).each(function() {
  $(this).text();
});

or this:

$('result', xml).each(function() {
  $(this).children("contactId").text();
});
Tomalak