I have the following xml. I am trying to parse this using gdataxml parser. I am able to parse the first part of the xml, <myBean> to </myBean>, but from the second part, from <trackBean>, it s becoming harder as the trackBean is recursing inside. I am finding it hard to develop a logic for that. I am stuck here for the 2nd day.
<return>
<myTrackBean>
<myBean>
<myStatus>false</myStatus>
<hisStatus>false</hisStatus>
<secondVcardBean>
<contactId>108</contactId>
<myNumber>KXUOYHGCIO</myNumber>
<userId>56</userId>
<version>1</version>
</secondVcardBean>
<myNumber>KXUOYHGCIO</myNumber>
</myBean>
<trackBean>
<myBean>
<myStatus>false</myStatus>
<hisStatus>false</hisStatus>
<secondVcardBean>
<contactId>105</contactId>
<myNumber>5D1X7XP6CW</myNumber>
<userId>54</userId>
<version>1</version>
</secondVcardBean>
<myNumber>5D1X7XP6CW</myNumber>
</myBean>
<trackBean>
<myBean>
<myStatus>false</myStatus>
<hisStatus>false</hisStatus>
<secondVcardBean>
<contactId>103</contactId>
<myNumber>0C3RM5UKBB</myNumber>
<userId>53</userId>
<version>8</version>
</secondVcardBean>
<myNumber>0C3RM5UKBB</myNumber>
</myBean>
</trackBean>
</trackBean>
</myTrackBean>
</return>
The following is the code I have used for parsing the first part, from the first <myBean> to <myBean>. How can I check whether a <trackBean> exists inside its parent <trackBean>
NSArray * array = [node nodesForXPath:@"//return/myTrackBean" error:nil];
int noOfmyTrackBean = [array count];
for(int i = 1; i<= noOfmyTrackBean; i++){
NSString *tempXmlData = [NSString stringWithFormat:@"//return/myTrackBean/myBean"];
NSString *myStatus = [node nodeStringForXPath:[tempXmlData stringByAppendingString:@"/myStatus"]];
NSString *hisStatus = [node nodeStringForXPath:[tempXmlData stringByAppendingString:@"/hisStatus"]];
NSString *contactId = [node nodeStringForXPath:[tempXmlData stringByAppendingString:@"/secondVcardBean/contactId"]];
NSString *myNumber = [node nodeStringForXPath:[tempXmlData stringByAppendingString:@"/secondVcardBean/myNumber"]];
I understand that the difficulty is in getting the <trackBean> child node inside <trackBean>
I think you dont need to worry a lot about recursion, as gdataxml seems to handle that part internally. You can just parse it normally as the parser object takes the count of the nodes that repeats inside itself. I dont know if its exactly what to you need, but it will definitely help you.
Hope this would help.