Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Um, isn't it obvious from <a href="http://search.cpan.org/perldoc/Mojo::DOM#SYNOPSIS" rel="nofollow">http://search.cpan.org/perldoc/Mojo::DOM#SYNOPSIS</a> ?</p> <pre><code>use Mojo::DOM; my $string =&lt;&lt;EOS; &lt;result&gt; &lt;cd&gt; &lt;artists&gt; &lt;artist class="1"&gt;Pumkinsingers&lt;/artist&gt; &lt;artist class="2"&gt;Max and Moritz&lt;/artist&gt; &lt;/artists&gt; &lt;title&gt;Hello, Hello&lt;/title&gt; &lt;/cd&gt; &lt;cd&gt; &lt;artists&gt; &lt;artist class="3"&gt;Green Trees&lt;/artist&gt; &lt;artist class="4"&gt;The Leons&lt;/artist&gt; &lt;/artists&gt; &lt;title&gt;The Shield&lt;/title&gt; &lt;/cd&gt; &lt;/result&gt; EOS my $dom = Mojo::DOM-&gt;new ($string ); my $xpath = '/result/cd[artists/artist[@class="2"]]/title'; print "\n1 ", $dom-&gt;find( $xpath ); print "\n2 ", $dom-&gt;find( '.2' ); print "\n3 ", $dom-&gt;find( 'artist.2' ); print "\n4 ", $dom-&gt;find( 'artists artist.2' ); print "\n5 ", $dom-&gt;find( 'artists artist.2' )-&gt;[0]-&gt;parent; print "\n6 ", $dom-&gt;find( 'artists artist.2' )-&gt;[0]-&gt;parent-&gt;parent; print "\n7 ", $dom-&gt;find( 'artists artist.2' )-&gt;[0]-&gt;parent-&gt;parent-&gt;find('title'); print "\n8 ", $dom-&gt;find( 'artists artist.2' )-&gt;[0]-&gt;parent-&gt;parent-&gt;find('title')-&gt;[0]-&gt;text; print "\n9 ", $dom-&gt;find( 'artists artist.2' )-&gt;[0]-&gt;parent-&gt;parent-&gt;find('title')-&gt;first-&gt;text; $dom-&gt;find( 'artists artist.2' )-&gt;each(sub { print "\n10 ", $_[0]-&gt;parent-&gt;parent-&gt;find('title')-&gt;first-&gt;text; }); __END__ 1 2 &lt;artist class="2"&gt;Max and Moritz&lt;/artist&gt; 3 &lt;artist class="2"&gt;Max and Moritz&lt;/artist&gt; 4 &lt;artist class="2"&gt;Max and Moritz&lt;/artist&gt; 5 &lt;artists&gt; &lt;artist class="1"&gt;Pumkinsingers&lt;/artist&gt; &lt;artist class="2"&gt;Max and Moritz&lt;/artist&gt; &lt;/artists&gt; 6 &lt;cd&gt; &lt;artists&gt; &lt;artist class="1"&gt;Pumkinsingers&lt;/artist&gt; &lt;artist class="2"&gt;Max and Moritz&lt;/artist&gt; &lt;/artists&gt; &lt;title&gt;Hello, Hello&lt;/title&gt; &lt;/cd&gt; 7 &lt;title&gt;Hello, Hello&lt;/title&gt; 8 Hello, Hello 9 Hello, Hello 10 Hello, Hello </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload