Reputation:
My XML object looks like this. I want to know how to look through it and fetch startdate and end date data. Later I want to compare and group appointments with same date together. I am good with JSON but I don't know how to manipulate XML. I am trying
$(xmlData).find("appointment")[0]['startdate']
$(xmlData).find("appointment")[0].find('startdate')
<appointment>
<appointmentid>2015032303585487505373377</appointmentid>
<startdate>20150323000000</startdate>
<enddate>20150323080000</enddate>
<description>Outside Office Hours</description>
<location>
<locationid></locationid>
<description></description>
</location>
<resource>
<resourceid>00000009</resourceid>
<description>John Doe</description>
<status>C</status>
</resource>
<colours>
<primary>eee</primary>
<secondary>eee</secondary>
<border>eee</border>
</colours>
</appointment>
<appointment>
<appointmentid>2015032303585487505273377</appointmentid>
<startdate>20150323000000</startdate>
<enddate>20150323080000</enddate>
<description>Outside Office Hours 1</description>
<location>
<locationid></locationid>
<description></description>
</location>
<resource>
<resourceid>00000009AJ</resourceid>
<description>Dr Nikhil</description>
<status>C</status>
</resource>
<colours>
<primary>eee</primary>
<secondary>eee</secondary>
<border>eee</border>
</colours>
</appointment>
<appointment>
<appointmentid>2015032303585487505273377</appointmentid>
<startdate>20150323000000</startdate>
<enddate>20150323080000</enddate>
<description>Outside Office Hours</description>
<location>
<locationid></locationid>
<description></description>
</location>
<resource>
<resourceid>0000000</resourceid>
<description>Dr Seema</description>
<status>C</status>
</resource>
<colours>
<primary>eee</primary>
<secondary>eee</secondary>
<border>eee</border>
</colours>
</appointment>
Upvotes: 1
Views: 32
Reputation: 388316
You need to use :eq() to get the appointment
at the given index. $(xmlData).find("appointment")[0]
will give an element reference which is not a jQuery object so .find()
will give an error
$(xmlData).find("appointment:eq(0) startdate").text()
Upvotes: 1