Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

A few comments:

You seem to think that in an XPath expression '//' denotes the top of the tree. It doesn't. The path you should be using is /Books/Book. '//' is more like a wildcard: //book will find all the book nodes in the document. Using '//' in your case forces the XPath engine to test basically all nodes in the document, while /Books/Book is much more efficient, and tests only the root and first-level children. For a good XPath tutorial have a look at

A couple of minor stylistic quibbles: I don't think you need to write foreach my $book ($xp->find('/Books/Book')->get_nodelist), as find in list context will return an array, so you can just write foreach my $book ($xp->find('/Books/Book')); you could also replace $book->find('author')->string_value by simply $book->findvalue('author'), which, besides being shorter, brings also the added benefit that it won't die if for some reason the author element is not present.

Finally, you wrote: the XPath Perl module which is part of the XML module. Not quite, XML::XPath is a module in the XML namespace, just like XML::Parser, XML::Simple or any other XML:: module.

In reply to Re: Using Perl XPath for converting Infopath XML files to Word Documents by mirod
in thread Using Perl XPath for converting Infopath XML files to Word Documents by karthik4perl

Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":

  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?

    What's my password?
    Create A New User
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (7)
    As of 2021-04-13 13:16 GMT
    Find Nodes?
      Voting Booth?

      No recent polls found