Xpath: Selecting all of an element type?

Posted by Johannes on Stack Overflow See other posts from Stack Overflow or by Johannes
Published on 2011-01-31T23:22:23Z Indexed on 2011/01/31 23:25 UTC
Read the original article Hit count: 318

Filed under:
|
|

I'm just starting to learn Xpath, I'm trying to write a line of code that will select all of the actors in EACH movie parent (through Java!). Below, I have an example of one movie, but there are multiple <Movie> elements, each with <Actor> elements.

<Movie Genre = 'Other'>
    <Title>Requiem For A Dream</Title>
    <ReleaseYear>2000</ReleaseYear>
    <Director>Darren Aronofsky</Director>
    <Actor Character = 'Sara Goldfarb'>Ellen Burstyn</Actor>
    <Actor Character = 'Harry Goldfarb'>Jared Leto</Actor>
    <Actor Character = 'Marion Silver'>Jennifer Connelly</Actor>
    <Actor Character = 'Tyrone C. Love'>Marlon Wayans</Actor>
</Movie>

Currently, I can only select the first <Actor> element of each <Movie> element -- is it possible to select all of them without using a for loop?

Here is my current line of code that displays the first <Actor> element of every <Movie> element:

System.out.println("Starring: " + xpath.evaluate("Actor", movieNode) + " as " + xpath.evaluate("Actor/@Character", movieNode) + "\n");

Any and all help if much appreciated!

© Stack Overflow or respective owner

Related posts about java

Related posts about xpath