Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to select multiple nodes in different levels?

Tags:

Having this (simplified) XML:

<?xml version="1.0" encoding="UTF-8"?>
<kml>
<Document>
        <Placemark>
            <name>Poly 1</name>
            <Polygon>
                        <coordinates>
                            -58.40844625779582,-34.60295278618136,0
                        </coordinates>
            </Polygon>
        </Placemark>
        <Placemark>
            <name>Poly 2</name>
            <Polygon>
                        <coordinates>
                            -58.40414334150432,-34.59992445476809,0
                        </coordinates>
            </Polygon>
        </Placemark>
</Document>
</kml>

How can I select the name and coordinates of each Placemark? Right now I can select their name with the following XPath expression:

//Document//Placemark//name

How can I select both without any other data?

like image 326
Alejandro García Iglesias Avatar asked Jun 14 '12 19:06

Alejandro García Iglesias


People also ask

How do you select multiple nodes?

There are a number of ways to select multiple nodes: Press and hold the Ctrl key to select multiple nodes. Press and hold the Shift key and drag a selection box across the nodes that you want to select.


1 Answers

You can use a union in your XPath expression. Just use the operator: |

//Document/Placemark/name | //Document/Placemark/Polygon/coordinates

Don't use the // (descendant axis) if you don't need to. Using //, this would also work: //name | //coordinates. It's better performance-wise to specify the exact path.

like image 156
toniedzwiedz Avatar answered Dec 22 '22 01:12

toniedzwiedz