我有以下xml。我正在尝试使用 gdataxml 解析器来解析它。我能够解析 xml 的第一部分<myBean>
to </myBean>
,但从第二部分 from 开始,随着内部递归<trackBean>
,它变得越来越难。trackBean
我发现很难为此制定逻辑。我被困在这里第二天。
<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>
以下是我用于解析第一部分的代码,从第一部分<myBean>
到 < myBean>
。如何检查 a 是否<trackBean>
存在于其父级中<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"]];
我知道困难在于将<trackBean>
子节点放入内部<trackBean>