Introduction to Perl & XPATH
What is XPATH
XPATH Terminology <ul><li>Items </li></ul><ul><ul><li>Nodes </li></ul></ul><ul><ul><li>Atomic values </li></ul></ul><ul><l...
XPATH Syntax != div - + * >= > = <= < or and | [] @ .. . // / Nodename
XML Sample <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><root> </li></ul><ul><li><...
Sample Script <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML;  </li></ul><ul><li># ...
Searching throughout on from the current  (xml libxml object)  node <ul><li>use strict; </li></ul><ul><li>use warnings; </...
Searching throughout the specified xml tree path <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use...
Playing with XPath positions <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li><...
Querying element values <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><...
Querying attributes <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><...
Examples
XML Sample <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><root> </li></ul><ul><li><...
Sample Script header <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul>...
Find all nodes <ul><li>## Find all nodes </li></ul><ul><li>foreach my $N ( $root->findnodes('node') ) { </li></ul><ul><li>...
Find first node <ul><li>## Find first node </li></ul><ul><li>foreach my $N ( $root->findnodes('node[1]') ) { </li></ul><ul...
Find last node <ul><li>## Find last node </li></ul><ul><li>foreach my $N ( $root->findnodes('node[last()]') ) { </li></ul>...
Find last-1 node <ul><li>## Find last-1 node </li></ul><ul><li>foreach my $N ( $root->findnodes('node[last()-1]') ) { </li...
Find all titles <ul><li>## Find all titles </li></ul><ul><li>foreach my $N ( $root->findnodes('//title') ) { </li></ul><ul...
Find all node/titles <ul><li>## Find all node/titles </li></ul><ul><li>foreach my $N ( $root->findnodes('node/title') ) { ...
Find all nodes/prices/text <ul><li>## Find all nodes/prices </li></ul><ul><li>foreach my $N ( $root->findnodes('/root/node...
Find all nodes/prices <ul><li>## Find all nodes/prices </li></ul><ul><li>foreach my $N ( $root->findnodes('/root/node/pric...
Find first node/title <ul><li>## Find first node/title </li></ul><ul><li>foreach my $N ( $root->findnodes('node[1]/title')...
Find all nodes/titles where price>50 <ul><li>## Find all nodes/titles where price>50 </li></ul><ul><li>foreach my $N ( $ro...
Find all nodes/titles where price<50 and price>40 <ul><li>## Find all nodes/titles where price<50 and price>40 </li></ul><...
Find all values for the attribute 'lang' <ul><li>## Find all values for the attribute 'lang' </li></ul><ul><li>foreach my ...
Find all titles with the attribute 'lang' <ul><li>## Find all titles with the attribute 'lang' </li></ul><ul><li>foreach m...
Find all titles with the attribute 'id' <ul><li>## Find all titles with the attribute 'id' </li></ul><ul><li>foreach my $N...
Find all titles with the attribute 'id=&quot;en&quot;' <ul><li>foreach my $N ( $root->findnodes('//title[@id=&quot;en&quot...
Find all titles with the attribute 'id' or with the attribute 'ooo' <ul><li>## Find all titles with the attribute 'id' or ...
[email_address]
Upcoming SlideShare
Loading in...5
×

Perl Xpath Lightning Talk

1,243

Published on

Published in: Technology, Business
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total Views
1,243
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide
  • What is XPath? XPath is a syntax for defining parts of an XML document XPath uses path expressions to navigate in XML documents XPath contains a library of standard functions XPath is a major element in several XML Based Technologies
  • Nodes In XPath, there are seven kinds of nodes: element, attribute, text, namespace, processing-instruction, comment, and document (root) nodes. XML documents are treated as trees of nodes. The root of the tree is called the document node (or root node). Atomic values Atomic values are nodes with no children or parent. Items Items are atomic values or nodes. Relationship of Nodes Parent Each element and attribute has one parent. Children Element nodes may have zero, one or more children. Siblings Nodes that have the same parent. Ancestors A node&apos;s parent, parent&apos;s parent, etc. Descendants A node&apos;s children, children&apos;s children, etc.
  • Selecting Nodes XPath uses path expressions to select nodes in an XML document. The node is selected by following a path or steps. The most useful path expressions are listed below: Expression Description nodename Selects all child nodes of the named node / Selects from the root node // Selects nodes in the document from the current node that match the selection no matter where they are . Selects the current node .. Selects the parent of the current node @ Selects attributes Wildcard Description Matches any element node Selecting Several Paths By using the | operator in an XPath expression you can select several paths.
  • Transcript of "Perl Xpath Lightning Talk"

    1. 1. Introduction to Perl & XPATH
    2. 2. What is XPATH
    3. 3. XPATH Terminology <ul><li>Items </li></ul><ul><ul><li>Nodes </li></ul></ul><ul><ul><li>Atomic values </li></ul></ul><ul><li>Relationship of Nodes </li></ul><ul><ul><li>Parent </li></ul></ul><ul><ul><li>Children </li></ul></ul><ul><ul><li>Siblings </li></ul></ul><ul><ul><li>Ancestors </li></ul></ul><ul><ul><li>Descendants </li></ul></ul>
    4. 4. XPATH Syntax != div - + * >= > = <= < or and | [] @ .. . // / Nodename
    5. 5. XML Sample <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><root> </li></ul><ul><li><node subject=&quot;Perl&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Mastering Perl</title> </li></ul><ul><li><author>brian d foy</author> </li></ul><ul><li><year>2007</year> </li></ul><ul><li><price>39.99</price> </li></ul><ul><li></node> </li></ul><ul><li><node subject=&quot;Perl&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Perl Best Practices</title> </li></ul><ul><li><author>Damian Conway</author> </li></ul><ul><li><year>2005</year> </li></ul><ul><li><price>39.95</price> </li></ul><ul><li></node> </li></ul><ul><li><node subject=&quot;OO&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Design Patterns: Elements of Reusable Object-Oriented Software</title> </li></ul><ul><li><author>Erich Gamma</author> </li></ul><ul><li><author>Richard Helm</author> </li></ul><ul><li><author>Ralph Johnson</author> </li></ul><ul><li><author>John Vlissides</author> </li></ul><ul><li><year>1994</year> </li></ul><ul><li><price>59.99</price> </li></ul><ul><li></node> </li></ul><ul><li><node subject=&quot;RegEx&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Mastering Regular Expressions , Third Edition</title> </li></ul><ul><li><author>Jeffrey E. F. Friedl</author> </li></ul><ul><li><year>2006</year> </li></ul><ul><li><price>44.99</price> </li></ul><ul><li></node> </li></ul><ul><li></root> </li></ul>
    6. 6. Sample Script <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li># To the daring win32 perl people: use the ppm command line </li></ul><ul><li># to install this package, the gui still doesn’t give the right answers </li></ul><ul><li># to the setup procedure. </li></ul><ul><li>#### Fetch libxml2.dll? [yes] yes </li></ul><ul><li>#### Where should libxml2.dll be placed? [C:Perlin] <ENTER> </li></ul><ul><li>my $RawXml = '<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><root> </li></ul><ul><li>.. </li></ul><ul><li></root>'; </li></ul><ul><li>my $parser = XML::LibXML->new(); </li></ul><ul><li>my $tree = $parser->parse_string($RawXml); </li></ul><ul><li>my $root = $tree->getDocumentElement(); </li></ul><ul><li>.. </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes(' XPATH_EXPRESSION ') ) { </li></ul><ul><li># print $N. &quot; &quot;; # XML::LibXML::Element=SCALAR(0x1a7a7d4) </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul>
    7. 7. Searching throughout on from the current (xml libxml object) node <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li>.. </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('//title') ) { </li></ul>
    8. 8. Searching throughout the specified xml tree path <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li>.. </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('title') ) { # won't work since no 'title' child objects at this xml tree level </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book/title') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('/bookshelf/book/price') ) { </li></ul>
    9. 9. Playing with XPath positions <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li>.. </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book[1]') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book[1]/title') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book[position()<3]') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book[last()-1]') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('book[last()]') ) { </li></ul>
    10. 10. Querying element values <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li>.. </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('/bookshelf/book[price>40 and price<50]/title') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('/bookshelf/book[price>50]/title') ) { </li></ul>
    11. 11. Querying attributes <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li>.. </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('//@lang') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('//title[@id]') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('//title[@lang]') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes('//title[@id | @ooo]') ) { </li></ul><ul><li>foreach my $N ( $bookshelf->findnodes( ' //title[@id= &quot; en &quot; ] ' ) ) { </li></ul>
    12. 12. Examples
    13. 13. XML Sample <ul><li><?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><root> </li></ul><ul><li><node subject=&quot;Perl&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Mastering Perl</title> </li></ul><ul><li><author>brian d foy</author> </li></ul><ul><li><year>2007</year> </li></ul><ul><li><price>39.99</price> </li></ul><ul><li></node> </li></ul><ul><li><node subject=&quot;Perl&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Perl Best Practices</title> </li></ul><ul><li><author>Damian Conway</author> </li></ul><ul><li><year>2005</year> </li></ul><ul><li><price>39.95</price> </li></ul><ul><li></node> </li></ul><ul><li><node subject=&quot;OO&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Design Patterns: Elements of Reusable Object-Oriented Software</title> </li></ul><ul><li><author>Erich Gamma</author> </li></ul><ul><li><author>Richard Helm</author> </li></ul><ul><li><author>Ralph Johnson</author> </li></ul><ul><li><author>John Vlissides</author> </li></ul><ul><li><year>1994</year> </li></ul><ul><li><price>59.99</price> </li></ul><ul><li></node> </li></ul><ul><li><node subject=&quot;RegEx&quot;> </li></ul><ul><li><title lang=&quot;en&quot;>Mastering Regular Expressions , Third Edition</title> </li></ul><ul><li><author>Jeffrey E. F. Friedl</author> </li></ul><ul><li><year>2006</year> </li></ul><ul><li><price>44.99</price> </li></ul><ul><li></node> </li></ul><ul><li></root> </li></ul>
    14. 14. Sample Script header <ul><li>use strict; </li></ul><ul><li>use warnings; </li></ul><ul><li>use XML::LibXML; </li></ul><ul><li>my $RawXml = '<?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?> </li></ul><ul><li><root> </li></ul><ul><li>.. </li></ul><ul><li></root>'; </li></ul><ul><li>my $parser = XML::LibXML->new(); </li></ul><ul><li>my $tree = $parser->parse_string($RawXml); </li></ul><ul><li>my $root = $tree->getDocumentElement(); </li></ul>
    15. 15. Find all nodes <ul><li>## Find all nodes </li></ul><ul><li>foreach my $N ( $root->findnodes('node') ) { </li></ul><ul><li>print $N. &quot; &quot;; </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## Output Sample: </li></ul><ul><li>## XML::LibXML::Element=SCALAR(0x1a7a7d4) </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Mastering Perl </li></ul><ul><li>## brian d foy </li></ul><ul><li>## 2007 </li></ul><ul><li>## 39.99 </li></ul><ul><li>## &quot; </li></ul><ul><li>## XML::LibXML::Element=SCALAR(0x1a7a7f4) </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Perl Best Practices </li></ul><ul><li>## Damian Conway </li></ul><ul><li>## 2005 </li></ul><ul><li>## 39.95 </li></ul><ul><li>## &quot; </li></ul><ul><li>## XML::LibXML::Element=SCALAR(0x1a7a814) </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Design Patterns: Elements of Reusable Object-Oriented Software </li></ul><ul><li>## Erich Gamma </li></ul><ul><li>## Richard Helm </li></ul><ul><li>## Ralph Johnson </li></ul><ul><li>## John Vlissides </li></ul><ul><li>## 1994 </li></ul><ul><li>## 59.99 </li></ul><ul><li>## &quot; </li></ul><ul><li>## XML::LibXML::Element=SCALAR(0x1a7a834) </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Mastering Regular Expressions , Third Edition </li></ul><ul><li>## Jeffrey E. F. Friedl </li></ul><ul><li>## 2006 </li></ul><ul><li>## 44.99 </li></ul><ul><li>## &quot; </li></ul>
    16. 16. Find first node <ul><li>## Find first node </li></ul><ul><li>foreach my $N ( $root->findnodes('node[1]') ) { </li></ul><ul><li>print $N->getAttribute(&quot;subject&quot;). &quot; &quot;; </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## Perl </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Mastering Perl </li></ul><ul><li>## brian d foy </li></ul><ul><li>## 2007 </li></ul><ul><li>## 39.99 </li></ul><ul><li>## &quot; </li></ul>
    17. 17. Find last node <ul><li>## Find last node </li></ul><ul><li>foreach my $N ( $root->findnodes('node[last()]') ) { </li></ul><ul><li>print $N->getAttribute(&quot;subject&quot;). &quot; &quot;; </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## RegEx </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Mastering Regular Expressions , Third Edition </li></ul><ul><li>## Jeffrey E. F. Friedl </li></ul><ul><li>## 2006 </li></ul><ul><li>## 44.99 </li></ul><ul><li>## &quot; </li></ul>
    18. 18. Find last-1 node <ul><li>## Find last-1 node </li></ul><ul><li>foreach my $N ( $root->findnodes('node[last()-1]') ) { </li></ul><ul><li>print $N->getAttribute(&quot;subject&quot;). &quot; &quot;; </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## OO </li></ul><ul><li>## node=&quot; </li></ul><ul><li>## Design Patterns: Elements of Reusable Object-Oriented Software </li></ul><ul><li>## Erich Gamma </li></ul><ul><li>## Richard Helm </li></ul><ul><li>## Ralph Johnson </li></ul><ul><li>## John Vlissides </li></ul><ul><li>## 1994 </li></ul><ul><li>## 59.99 </li></ul><ul><li>## &quot; </li></ul>
    19. 19. Find all titles <ul><li>## Find all titles </li></ul><ul><li>foreach my $N ( $root->findnodes('//title') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Mastering Perl&quot; </li></ul><ul><li>## title=&quot;Perl Best Practices&quot; </li></ul><ul><li>## title=&quot;Design Patterns: Elements of Reusable Object-Oriented Software&quot; </li></ul><ul><li>## title=&quot;Mastering Regular Expressions , Third Edition&quot; </li></ul><ul><li>## title=&quot;Perl Best Practices duplicate&quot; </li></ul>
    20. 20. Find all node/titles <ul><li>## Find all node/titles </li></ul><ul><li>foreach my $N ( $root->findnodes('node/title') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Mastering Perl&quot; </li></ul><ul><li>## title=&quot;Perl Best Practices&quot; </li></ul><ul><li>## title=&quot;Design Patterns: Elements of Reusable Object-Oriented Software&quot; </li></ul><ul><li>## title=&quot;Mastering Regular Expressions , Third Edition&quot; </li></ul>
    21. 21. Find all nodes/prices/text <ul><li>## Find all nodes/prices </li></ul><ul><li>foreach my $N ( $root->findnodes('/root/node/price/text()') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## #text=&quot;39.99&quot; </li></ul><ul><li>## #text=&quot;39.95&quot; </li></ul><ul><li>## #text=&quot;59.99&quot; </li></ul><ul><li>## #text=&quot;44.99&quot; </li></ul>
    22. 22. Find all nodes/prices <ul><li>## Find all nodes/prices </li></ul><ul><li>foreach my $N ( $root->findnodes('/root/node/price') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## price=&quot;39.99&quot; </li></ul><ul><li>## price=&quot;39.95&quot; </li></ul><ul><li>## price=&quot;59.99&quot; </li></ul><ul><li>## price=&quot;44.99&quot; </li></ul>
    23. 23. Find first node/title <ul><li>## Find first node/title </li></ul><ul><li>foreach my $N ( $root->findnodes('node[1]/title') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Mastering Perl&quot; </li></ul>
    24. 24. Find all nodes/titles where price>50 <ul><li>## Find all nodes/titles where price>50 </li></ul><ul><li>foreach my $N ( $root->findnodes('/root/node[price>50]/title') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Design Patterns: Elements of Reusable Object-Oriented Software&quot; </li></ul>
    25. 25. Find all nodes/titles where price<50 and price>40 <ul><li>## Find all nodes/titles where price<50 and price>40 </li></ul><ul><li>foreach my $N ( $root->findnodes('/root/node[price>40 and price<50]/title') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Mastering Regular Expressions , Third Edition“ </li></ul><ul><li>## title=&quot;Design Patterns: Elements of Reusable Object-Oriented Software&quot; </li></ul>
    26. 26. Find all values for the attribute 'lang' <ul><li>## Find all values for the attribute 'lang' </li></ul><ul><li>foreach my $N ( $root->findnodes('//@lang') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## lang=&quot;en&quot; </li></ul><ul><li>## lang=&quot;en&quot; </li></ul><ul><li>## lang=&quot;en&quot; </li></ul><ul><li>## lang=&quot;en&quot; </li></ul>
    27. 27. Find all titles with the attribute 'lang' <ul><li>## Find all titles with the attribute 'lang' </li></ul><ul><li>foreach my $N ( $root->findnodes('//title[@lang]') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Mastering Perl&quot; </li></ul><ul><li>## title=&quot;Perl Best Practices&quot; </li></ul><ul><li>## title=&quot;Design Patterns: Elements of Reusable Object-Oriented Software&quot; </li></ul><ul><li>## title=&quot;Mastering Regular Expressions , Third Edition&quot; </li></ul>
    28. 28. Find all titles with the attribute 'id' <ul><li>## Find all titles with the attribute 'id' </li></ul><ul><li>foreach my $N ( $root->findnodes('//title[@id]') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Perl Best Practices duplicate&quot; </li></ul>
    29. 29. Find all titles with the attribute 'id=&quot;en&quot;' <ul><li>foreach my $N ( $root->findnodes('//title[@id=&quot;en&quot;]') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Perl Best Practices duplicate&quot; </li></ul>
    30. 30. Find all titles with the attribute 'id' or with the attribute 'ooo' <ul><li>## Find all titles with the attribute 'id' or with the attribute 'ooo' </li></ul><ul><li>foreach my $N ( $root->findnodes('//title[@id | @ooo]') ) { </li></ul><ul><li>print $N->getName() . &quot;=&quot; . &quot;&quot;&quot; . $N->textContent() . &quot;&quot;&quot; . &quot; &quot;; </li></ul><ul><li>} </li></ul><ul><li>## title=&quot;Perl Best Practices duplicate&quot; </li></ul>
    31. 31. [email_address]

    ×