Note that there are some explanatory texts on larger screens.

plurals
  1. POTBXML parsing, unable to find nextSibling
    text
    copied!<p>I've to parse this XML from the web:</p> <pre><code>&lt;trasporto&gt; &lt;condizioni id="0"&gt; &lt;data&gt; &lt;/data&gt; &lt;titolo&gt; &lt;/titolo&gt; &lt;testo&gt; &lt;/testo&gt; &lt;sezione&gt; &lt;/sezione&gt; &lt;/condizioni&gt; &lt;condizioni id="1"&gt; &lt;data&gt; &lt;/data&gt; &lt;titolo&gt; &lt;/titolo&gt; &lt;testo&gt; &lt;/testo&gt; &lt;sezione&gt; &lt;/sezione&gt; &lt;/condizioni&gt; ........ ........ ........ &lt;/trasporto&gt; </code></pre> <p>and I need the fields, <strong>data / titolo / testo / sezione</strong> from each <strong>condizioni</strong></p> <p>Here's my code:</p> <pre><code> .............. //responseString contains the text fetched from the web NSData *data = [responseString dataUsingEncoding:NSUTF8StringEncoding]; tbxml = [[TBXML alloc]initWithXMLData:data]; if (tbxml.rootXMLElement) [self traverseElement:tbxml.rootXMLElement]; [tbxml release]; } -(void) traverseElement:(TBXMLElement *)element { NSMutableArray *dataArr = [[NSMutableArray alloc]init]; NSMutableArray *titoloArr = [[NSMutableArray alloc]init]; NSMutableArray *testoArr = [[NSMutableArray alloc]init]; NSMutableArray *sezioneArr = [[NSMutableArray alloc]init]; do { NSLog(@"%@",[TBXML elementName:element]); if (element-&gt;firstChild) [self traverseElement:element-&gt;firstChild]; if ([[TBXML elementName:element] isEqualToString:@"trasporto"]) { TBXMLElement *condizioni = [TBXML childElementNamed:@"condizioni" parentElement:element]; TBXMLElement *data = [TBXML childElementNamed:@"data" parentElement:condizioni]; TBXMLElement *titolo = [TBXML childElementNamed:@"titolo" parentElement:condizioni]; TBXMLElement *testo = [TBXML childElementNamed:@"testo" parentElement:condizioni]; TBXMLElement *sezione = [TBXML childElementNamed:@"sezione" parentElement:condizioni]; [dataArr addObject:[TBXML textForElement:data]]; [titoloArr addObject:[TBXML textForElement:titolo]]; [testoArr addObject:[TBXML textForElement:testo]]; [sezioneArr addObject:[TBXML textForElement:sezione]]; NSLog(@"data: %@",dataArr);// [TBXML textForElement:data]); NSLog(@"titolo: %@",titoloArr);//[TBXML textForElement:titolo]); NSLog(@"testo: %@",testoArr);//[TBXML textForElement:testo]); NSLog(@"sezione: %@",sezioneArr);//[TBXML textForElement:sezione]); // condizioni = condizioni -&gt; nextSibling; } } while ((element = element-&gt;nextSibling)); } </code></pre> <p>But in this way I can only parse the first <strong>condizioni</strong>, the one with id=0. It seems I'm unable to find the next sibling. Where's my mistake?!?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload