I'm parsing an xml file using TBXML. my xml is like this:
Code:
<locations>
<location>
<id>1</id>
<name>hello</name>
</location>
<location>
...
</locations>
all works fine, but there is a big problem: sometimes the xml can "skip" the "name" tag, so, for example, there is something like this:
Code:
...
</location>
<location>
<id>43</id>
</location>
<location>
...
where is the problem? that using this code
Code:
TBXMLElement *location = [TBXML childElementNamed:@"location" parentElement:root];
while (location){
TBXMLElement *id = [TBXML childElementNamed:@"id" parentElement:location];
TBXMLElement *name = [TBXML childElementNamed:@"name" parentElement:location];
... //do something
location = location -> nextSibling;
}
the app crashes reading the tag "name" because sometimes there isn't...
How can i solve it??
thanks!