xpath get many nodes at once












0















I'm a newbie to Xpath and can't solve this for a few hours now.
I've got an xml response from maps.googleapis.com/maps/api/geocode/xml?latlng=51,0
which contains multiple "results", and each "result" may contain multiple "address_component".
Response is parsed in specific prog, and it can't use concatenations like



/GeocodeResponse[1]/status[text()='OK'] | /GeocodeResponse[1]/result[1]/type | /GeocodeResponse[1]/result[1]/address_component[1]...


and it can be done only through one request like



/GeocodeResponse[1]/[self::status[text()='OK'] or self::result[1]/type or self::result[1]/address_component[1]] 


but this path returns all "results", while I need only the first one and nodes inside it("type", "formatted_address") and sub-nodes ("long_name","short_name") of a certain "address_component"'s nodes in it.
Output example:



GeocodeResponse[1]/status
GeocodeResponse[1]/result[1]/type[1]
GeocodeResponse[1]/result[1]/formatted_address[1]
GeocodeResponse[1]/result[1]/address_component/short_name - where "address_component" contains "types" with text ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code')


Source xml response looks like:



`<GeocodeResponse>
<status>OK</status>
<result>
<type>establishment</type>
<type>point_of_interest</type>
<formatted_address>2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK</formatted_address>
<address_component>
<long_name>2</long_name>
<short_name>2</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>Hazel Grove</long_name>
<short_name>Hazel Grove</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Radcliffe</long_name>
<short_name>Radcliffe</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>M26 1DD</long_name>
<short_name>M26 1DD</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>51.0000000</lat>
<lng>0.0000000</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>50.9986510</lat>
<lng>-0.0013490</lng>
</southwest>
<northeast>
<lat>51.0013490</lat>
<lng>0.0013490</lng>
</northeast>
</viewport>
</geometry>
<place_id>ChIJ_8dXPfiLdUgR9wQihY2gsgk</place_id>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, United Kingdom</compound_code>
</plus_code>
</result>
<result>
<type>postal_code</type>
<formatted_address>Uckfield TN22 3QS, UK</formatted_address>
<address_component>
<long_name>TN22 3QS</long_name>
<short_name>TN22 3QS</short_name>
<type>postal_code</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>50.9973315</lat>
<lng>0.0079172</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</bounds>
</geometry>
<place_id>ChIJqWgEbhpg30cRL6VL5HVT3NI</place_id>
</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, UK</compound_code>
</plus_code>
</GeocodeResponse>


can anyone suggest me how to achieve this please?



e.g.: vals to grab










share|improve this question

























  • Can you share current and expected result explicitly?

    – Andersson
    Nov 21 '18 at 8:29











  • Please show what is your expected output. Your Xpath and description is not fully clear to understand.

    – Amrendra Kumar
    Nov 21 '18 at 8:55











  • I need to garb: GeocodeResponse[1]/status; GeocodeResponse[1]/result[1]/type[1]; GeocodeResponse[1]/result[1]/formatted_address[1]; GeocodeResponse[1]/result[1]/address_component/short_name - where address_component contains types in ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code').

    – user241841
    Nov 21 '18 at 9:13











  • fail example is xpath /GeocodeResponse[1]/[self::status[text()='OK']/text() or self::result/address_component/long_name[text()='Hazel Grove']] returns "status" and only first "result". But I want to explicitly result[1] and not the whole "result" node, but only matched "address_component/long_name"

    – user241841
    Nov 21 '18 at 9:38


















0















I'm a newbie to Xpath and can't solve this for a few hours now.
I've got an xml response from maps.googleapis.com/maps/api/geocode/xml?latlng=51,0
which contains multiple "results", and each "result" may contain multiple "address_component".
Response is parsed in specific prog, and it can't use concatenations like



/GeocodeResponse[1]/status[text()='OK'] | /GeocodeResponse[1]/result[1]/type | /GeocodeResponse[1]/result[1]/address_component[1]...


and it can be done only through one request like



/GeocodeResponse[1]/[self::status[text()='OK'] or self::result[1]/type or self::result[1]/address_component[1]] 


but this path returns all "results", while I need only the first one and nodes inside it("type", "formatted_address") and sub-nodes ("long_name","short_name") of a certain "address_component"'s nodes in it.
Output example:



GeocodeResponse[1]/status
GeocodeResponse[1]/result[1]/type[1]
GeocodeResponse[1]/result[1]/formatted_address[1]
GeocodeResponse[1]/result[1]/address_component/short_name - where "address_component" contains "types" with text ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code')


Source xml response looks like:



`<GeocodeResponse>
<status>OK</status>
<result>
<type>establishment</type>
<type>point_of_interest</type>
<formatted_address>2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK</formatted_address>
<address_component>
<long_name>2</long_name>
<short_name>2</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>Hazel Grove</long_name>
<short_name>Hazel Grove</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Radcliffe</long_name>
<short_name>Radcliffe</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>M26 1DD</long_name>
<short_name>M26 1DD</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>51.0000000</lat>
<lng>0.0000000</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>50.9986510</lat>
<lng>-0.0013490</lng>
</southwest>
<northeast>
<lat>51.0013490</lat>
<lng>0.0013490</lng>
</northeast>
</viewport>
</geometry>
<place_id>ChIJ_8dXPfiLdUgR9wQihY2gsgk</place_id>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, United Kingdom</compound_code>
</plus_code>
</result>
<result>
<type>postal_code</type>
<formatted_address>Uckfield TN22 3QS, UK</formatted_address>
<address_component>
<long_name>TN22 3QS</long_name>
<short_name>TN22 3QS</short_name>
<type>postal_code</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>50.9973315</lat>
<lng>0.0079172</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</bounds>
</geometry>
<place_id>ChIJqWgEbhpg30cRL6VL5HVT3NI</place_id>
</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, UK</compound_code>
</plus_code>
</GeocodeResponse>


can anyone suggest me how to achieve this please?



e.g.: vals to grab










share|improve this question

























  • Can you share current and expected result explicitly?

    – Andersson
    Nov 21 '18 at 8:29











  • Please show what is your expected output. Your Xpath and description is not fully clear to understand.

    – Amrendra Kumar
    Nov 21 '18 at 8:55











  • I need to garb: GeocodeResponse[1]/status; GeocodeResponse[1]/result[1]/type[1]; GeocodeResponse[1]/result[1]/formatted_address[1]; GeocodeResponse[1]/result[1]/address_component/short_name - where address_component contains types in ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code').

    – user241841
    Nov 21 '18 at 9:13











  • fail example is xpath /GeocodeResponse[1]/[self::status[text()='OK']/text() or self::result/address_component/long_name[text()='Hazel Grove']] returns "status" and only first "result". But I want to explicitly result[1] and not the whole "result" node, but only matched "address_component/long_name"

    – user241841
    Nov 21 '18 at 9:38
















0












0








0








I'm a newbie to Xpath and can't solve this for a few hours now.
I've got an xml response from maps.googleapis.com/maps/api/geocode/xml?latlng=51,0
which contains multiple "results", and each "result" may contain multiple "address_component".
Response is parsed in specific prog, and it can't use concatenations like



/GeocodeResponse[1]/status[text()='OK'] | /GeocodeResponse[1]/result[1]/type | /GeocodeResponse[1]/result[1]/address_component[1]...


and it can be done only through one request like



/GeocodeResponse[1]/[self::status[text()='OK'] or self::result[1]/type or self::result[1]/address_component[1]] 


but this path returns all "results", while I need only the first one and nodes inside it("type", "formatted_address") and sub-nodes ("long_name","short_name") of a certain "address_component"'s nodes in it.
Output example:



GeocodeResponse[1]/status
GeocodeResponse[1]/result[1]/type[1]
GeocodeResponse[1]/result[1]/formatted_address[1]
GeocodeResponse[1]/result[1]/address_component/short_name - where "address_component" contains "types" with text ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code')


Source xml response looks like:



`<GeocodeResponse>
<status>OK</status>
<result>
<type>establishment</type>
<type>point_of_interest</type>
<formatted_address>2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK</formatted_address>
<address_component>
<long_name>2</long_name>
<short_name>2</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>Hazel Grove</long_name>
<short_name>Hazel Grove</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Radcliffe</long_name>
<short_name>Radcliffe</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>M26 1DD</long_name>
<short_name>M26 1DD</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>51.0000000</lat>
<lng>0.0000000</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>50.9986510</lat>
<lng>-0.0013490</lng>
</southwest>
<northeast>
<lat>51.0013490</lat>
<lng>0.0013490</lng>
</northeast>
</viewport>
</geometry>
<place_id>ChIJ_8dXPfiLdUgR9wQihY2gsgk</place_id>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, United Kingdom</compound_code>
</plus_code>
</result>
<result>
<type>postal_code</type>
<formatted_address>Uckfield TN22 3QS, UK</formatted_address>
<address_component>
<long_name>TN22 3QS</long_name>
<short_name>TN22 3QS</short_name>
<type>postal_code</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>50.9973315</lat>
<lng>0.0079172</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</bounds>
</geometry>
<place_id>ChIJqWgEbhpg30cRL6VL5HVT3NI</place_id>
</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, UK</compound_code>
</plus_code>
</GeocodeResponse>


can anyone suggest me how to achieve this please?



e.g.: vals to grab










share|improve this question
















I'm a newbie to Xpath and can't solve this for a few hours now.
I've got an xml response from maps.googleapis.com/maps/api/geocode/xml?latlng=51,0
which contains multiple "results", and each "result" may contain multiple "address_component".
Response is parsed in specific prog, and it can't use concatenations like



/GeocodeResponse[1]/status[text()='OK'] | /GeocodeResponse[1]/result[1]/type | /GeocodeResponse[1]/result[1]/address_component[1]...


and it can be done only through one request like



/GeocodeResponse[1]/[self::status[text()='OK'] or self::result[1]/type or self::result[1]/address_component[1]] 


but this path returns all "results", while I need only the first one and nodes inside it("type", "formatted_address") and sub-nodes ("long_name","short_name") of a certain "address_component"'s nodes in it.
Output example:



GeocodeResponse[1]/status
GeocodeResponse[1]/result[1]/type[1]
GeocodeResponse[1]/result[1]/formatted_address[1]
GeocodeResponse[1]/result[1]/address_component/short_name - where "address_component" contains "types" with text ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code')


Source xml response looks like:



`<GeocodeResponse>
<status>OK</status>
<result>
<type>establishment</type>
<type>point_of_interest</type>
<formatted_address>2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK</formatted_address>
<address_component>
<long_name>2</long_name>
<short_name>2</short_name>
<type>street_number</type>
</address_component>
<address_component>
<long_name>Hazel Grove</long_name>
<short_name>Hazel Grove</short_name>
<type>route</type>
</address_component>
<address_component>
<long_name>Radcliffe</long_name>
<short_name>Radcliffe</short_name>
<type>locality</type>
<type>political</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<address_component>
<long_name>M26 1DD</long_name>
<short_name>M26 1DD</short_name>
<type>postal_code</type>
</address_component>
<geometry>
<location>
<lat>51.0000000</lat>
<lng>0.0000000</lng>
</location>
<location_type>ROOFTOP</location_type>
<viewport>
<southwest>
<lat>50.9986510</lat>
<lng>-0.0013490</lng>
</southwest>
<northeast>
<lat>51.0013490</lat>
<lng>0.0013490</lng>
</northeast>
</viewport>
</geometry>
<place_id>ChIJ_8dXPfiLdUgR9wQihY2gsgk</place_id>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, United Kingdom</compound_code>
</plus_code>
</result>
<result>
<type>postal_code</type>
<formatted_address>Uckfield TN22 3QS, UK</formatted_address>
<address_component>
<long_name>TN22 3QS</long_name>
<short_name>TN22 3QS</short_name>
<type>postal_code</type>
</address_component>
<address_component>
<long_name>Uckfield</long_name>
<short_name>Uckfield</short_name>
<type>postal_town</type>
</address_component>
<address_component>
<long_name>East Sussex</long_name>
<short_name>East Sussex</short_name>
<type>administrative_area_level_2</type>
<type>political</type>
</address_component>
<address_component>
<long_name>England</long_name>
<short_name>England</short_name>
<type>administrative_area_level_1</type>
<type>political</type>
</address_component>
<address_component>
<long_name>United Kingdom</long_name>
<short_name>GB</short_name>
<type>country</type>
<type>political</type>
</address_component>
<geometry>
<location>
<lat>50.9973315</lat>
<lng>0.0079172</lng>
</location>
<location_type>APPROXIMATE</location_type>
<viewport>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</viewport>
<bounds>
<southwest>
<lat>50.9959291</lat>
<lng>-0.0003802</lng>
</southwest>
<northeast>
<lat>51.0023266</lat>
<lng>0.0087596</lng>
</northeast>
</bounds>
</geometry>
<place_id>ChIJqWgEbhpg30cRL6VL5HVT3NI</place_id>
</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<result>...</result>
<plus_code>
<global_code>9F322222+22</global_code>
<compound_code>2222+22 Sheffield Green, UK</compound_code>
</plus_code>
</GeocodeResponse>


can anyone suggest me how to achieve this please?



e.g.: vals to grab







google-maps xpath xml-parsing






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 12:35







user241841

















asked Nov 21 '18 at 7:35









user241841user241841

12




12













  • Can you share current and expected result explicitly?

    – Andersson
    Nov 21 '18 at 8:29











  • Please show what is your expected output. Your Xpath and description is not fully clear to understand.

    – Amrendra Kumar
    Nov 21 '18 at 8:55











  • I need to garb: GeocodeResponse[1]/status; GeocodeResponse[1]/result[1]/type[1]; GeocodeResponse[1]/result[1]/formatted_address[1]; GeocodeResponse[1]/result[1]/address_component/short_name - where address_component contains types in ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code').

    – user241841
    Nov 21 '18 at 9:13











  • fail example is xpath /GeocodeResponse[1]/[self::status[text()='OK']/text() or self::result/address_component/long_name[text()='Hazel Grove']] returns "status" and only first "result". But I want to explicitly result[1] and not the whole "result" node, but only matched "address_component/long_name"

    – user241841
    Nov 21 '18 at 9:38





















  • Can you share current and expected result explicitly?

    – Andersson
    Nov 21 '18 at 8:29











  • Please show what is your expected output. Your Xpath and description is not fully clear to understand.

    – Amrendra Kumar
    Nov 21 '18 at 8:55











  • I need to garb: GeocodeResponse[1]/status; GeocodeResponse[1]/result[1]/type[1]; GeocodeResponse[1]/result[1]/formatted_address[1]; GeocodeResponse[1]/result[1]/address_component/short_name - where address_component contains types in ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code').

    – user241841
    Nov 21 '18 at 9:13











  • fail example is xpath /GeocodeResponse[1]/[self::status[text()='OK']/text() or self::result/address_component/long_name[text()='Hazel Grove']] returns "status" and only first "result". But I want to explicitly result[1] and not the whole "result" node, but only matched "address_component/long_name"

    – user241841
    Nov 21 '18 at 9:38



















Can you share current and expected result explicitly?

– Andersson
Nov 21 '18 at 8:29





Can you share current and expected result explicitly?

– Andersson
Nov 21 '18 at 8:29













Please show what is your expected output. Your Xpath and description is not fully clear to understand.

– Amrendra Kumar
Nov 21 '18 at 8:55





Please show what is your expected output. Your Xpath and description is not fully clear to understand.

– Amrendra Kumar
Nov 21 '18 at 8:55













I need to garb: GeocodeResponse[1]/status; GeocodeResponse[1]/result[1]/type[1]; GeocodeResponse[1]/result[1]/formatted_address[1]; GeocodeResponse[1]/result[1]/address_component/short_name - where address_component contains types in ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code').

– user241841
Nov 21 '18 at 9:13





I need to garb: GeocodeResponse[1]/status; GeocodeResponse[1]/result[1]/type[1]; GeocodeResponse[1]/result[1]/formatted_address[1]; GeocodeResponse[1]/result[1]/address_component/short_name - where address_component contains types in ('street_number', 'route', 'locality', 'administrative_area_level_1', 'postal_code').

– user241841
Nov 21 '18 at 9:13













fail example is xpath /GeocodeResponse[1]/[self::status[text()='OK']/text() or self::result/address_component/long_name[text()='Hazel Grove']] returns "status" and only first "result". But I want to explicitly result[1] and not the whole "result" node, but only matched "address_component/long_name"

– user241841
Nov 21 '18 at 9:38







fail example is xpath /GeocodeResponse[1]/[self::status[text()='OK']/text() or self::result/address_component/long_name[text()='Hazel Grove']] returns "status" and only first "result". But I want to explicitly result[1] and not the whole "result" node, but only matched "address_component/long_name"

– user241841
Nov 21 '18 at 9:38














1 Answer
1






active

oldest

votes


















0














Based from what I can understand from your question including your comments, is this what you want?



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]


It gets the first result child node of GeocodeResponse node (which has a child status = OK). With the result node having a descendant long_name (which has a value of 'Hazel Grove').



EDIT



Please have this xpath instead:



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]/(preceding-sibling::status|type[1]|formatted_address[1]|address_component/short_name[../type='street_number' or ../type='route' or ../type='locality' or ../type='administrative_area_level_1' or ../type='postal_code'])


base on my testing on your XML, it outputs



OK
establishment
2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK
2
Hazel Grove
Radcliffe
England
M26 1DD





share|improve this answer


























  • I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

    – user241841
    Nov 23 '18 at 12:40













  • I have edited my answer. It's a long xpath, sorry.

    – Joel M. Lamsen
    Nov 23 '18 at 13:03











  • tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

    – user241841
    Nov 26 '18 at 8:55













  • I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

    – Joel M. Lamsen
    Nov 26 '18 at 9:36











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407230%2fxpath-get-many-nodes-at-once%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Based from what I can understand from your question including your comments, is this what you want?



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]


It gets the first result child node of GeocodeResponse node (which has a child status = OK). With the result node having a descendant long_name (which has a value of 'Hazel Grove').



EDIT



Please have this xpath instead:



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]/(preceding-sibling::status|type[1]|formatted_address[1]|address_component/short_name[../type='street_number' or ../type='route' or ../type='locality' or ../type='administrative_area_level_1' or ../type='postal_code'])


base on my testing on your XML, it outputs



OK
establishment
2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK
2
Hazel Grove
Radcliffe
England
M26 1DD





share|improve this answer


























  • I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

    – user241841
    Nov 23 '18 at 12:40













  • I have edited my answer. It's a long xpath, sorry.

    – Joel M. Lamsen
    Nov 23 '18 at 13:03











  • tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

    – user241841
    Nov 26 '18 at 8:55













  • I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

    – Joel M. Lamsen
    Nov 26 '18 at 9:36
















0














Based from what I can understand from your question including your comments, is this what you want?



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]


It gets the first result child node of GeocodeResponse node (which has a child status = OK). With the result node having a descendant long_name (which has a value of 'Hazel Grove').



EDIT



Please have this xpath instead:



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]/(preceding-sibling::status|type[1]|formatted_address[1]|address_component/short_name[../type='street_number' or ../type='route' or ../type='locality' or ../type='administrative_area_level_1' or ../type='postal_code'])


base on my testing on your XML, it outputs



OK
establishment
2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK
2
Hazel Grove
Radcliffe
England
M26 1DD





share|improve this answer


























  • I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

    – user241841
    Nov 23 '18 at 12:40













  • I have edited my answer. It's a long xpath, sorry.

    – Joel M. Lamsen
    Nov 23 '18 at 13:03











  • tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

    – user241841
    Nov 26 '18 at 8:55













  • I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

    – Joel M. Lamsen
    Nov 26 '18 at 9:36














0












0








0







Based from what I can understand from your question including your comments, is this what you want?



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]


It gets the first result child node of GeocodeResponse node (which has a child status = OK). With the result node having a descendant long_name (which has a value of 'Hazel Grove').



EDIT



Please have this xpath instead:



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]/(preceding-sibling::status|type[1]|formatted_address[1]|address_component/short_name[../type='street_number' or ../type='route' or ../type='locality' or ../type='administrative_area_level_1' or ../type='postal_code'])


base on my testing on your XML, it outputs



OK
establishment
2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK
2
Hazel Grove
Radcliffe
England
M26 1DD





share|improve this answer















Based from what I can understand from your question including your comments, is this what you want?



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]


It gets the first result child node of GeocodeResponse node (which has a child status = OK). With the result node having a descendant long_name (which has a value of 'Hazel Grove').



EDIT



Please have this xpath instead:



//GeocodeResponse[status='OK']/result[address_component/long_name[.='Hazel Grove']][1]/(preceding-sibling::status|type[1]|formatted_address[1]|address_component/short_name[../type='street_number' or ../type='route' or ../type='locality' or ../type='administrative_area_level_1' or ../type='postal_code'])


base on my testing on your XML, it outputs



OK
establishment
2 Hazel Grove, Radcliffe, Uckfield M26 1DD, UK
2
Hazel Grove
Radcliffe
England
M26 1DD






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 13:03

























answered Nov 22 '18 at 7:13









Joel M. LamsenJoel M. Lamsen

6,5021814




6,5021814













  • I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

    – user241841
    Nov 23 '18 at 12:40













  • I have edited my answer. It's a long xpath, sorry.

    – Joel M. Lamsen
    Nov 23 '18 at 13:03











  • tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

    – user241841
    Nov 26 '18 at 8:55













  • I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

    – Joel M. Lamsen
    Nov 26 '18 at 9:36



















  • I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

    – user241841
    Nov 23 '18 at 12:40













  • I have edited my answer. It's a long xpath, sorry.

    – Joel M. Lamsen
    Nov 23 '18 at 13:03











  • tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

    – user241841
    Nov 26 '18 at 8:55













  • I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

    – Joel M. Lamsen
    Nov 26 '18 at 9:36

















I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

– user241841
Nov 23 '18 at 12:40







I need not a whole "result" node, but only some of it's children and grand-children. result must be a node-set. added a pic to a topiс with needed vals hilighted

– user241841
Nov 23 '18 at 12:40















I have edited my answer. It's a long xpath, sorry.

– Joel M. Lamsen
Nov 23 '18 at 13:03





I have edited my answer. It's a long xpath, sorry.

– Joel M. Lamsen
Nov 23 '18 at 13:03













tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

– user241841
Nov 26 '18 at 8:55







tested your example (no matter how long it is) at whitebeam.org/library/guide/TechNotes/xpathtestbed.rhtm and it again grabs only "result" node entirely

– user241841
Nov 26 '18 at 8:55















I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

– Joel M. Lamsen
Nov 26 '18 at 9:36





I have tested it again and it shows the same result. Visit this link (goo.gl/2NkHqn)

– Joel M. Lamsen
Nov 26 '18 at 9:36


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53407230%2fxpath-get-many-nodes-at-once%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]