views:

27

answers:

1

Hi,

I am trying to parse an xml using GdataXML

I have a query which is not working and I wonder why:

<address_component>
  <long_name>Mars</long_name> 
  <short_name>Mars</short_name> 
  <type>route</type> 
</address_component>

I want to save the long_name where the type is route and I am using this query

/*[name() = 'address_component']
 /*[name() = 'type' and text() = 'route']
  /*[name() = 'long_name']

What am I doing wrong here?

===========

Is there a way for GDataXML to parse the xml line for line? is there a way other than running the xml a few times into an array?

A: 

I want to save the long_name where the type is route

This XPath expression should work:

/address_component[type='route']/long_name

Meanning: a long_name element child of an address_component root element having a type child element with 'route' string value.

Alejandro
next problem my code is: NSArray *street = [doc nodesForXPath:@"//GeocodeResponse/result/address_component[type = 'route'/long_name" error:nil]; NSLog(@"count:", [street count]); But when I run this my app crashes
Nico
@Nico: Be sure there is no typo in your code: `"//GeocodeResponse/result/address_component[type = 'route'/long_name"` should be `"//GeocodeResponse/result/address_component[type = 'route']/long_name"`. Second, is there any namespace declaration in the source XML, as `xmlns:XXX="..."`?
Alejandro
Nico
@Nico: In my test, it result in 10 `long_name` elements form all the 60. Also, you don't need the starting `//` operator, just `/`.
Alejandro
@Nico: I think you should ask an specific `objective-C` question with your code.
Alejandro
With NSXML I am going trough the xml line by line is that also possible with GDataXML?
Nico