Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: Using Perl XPath for converting Infopath XML files to Word Documents

by mirod (Canon)
on Jan 13, 2005 at 13:08 UTC ( #421956=note: print w/ replies, xml ) Need Help??


in reply to Using Perl XPath for converting Infopath XML files to Word Documents

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 zvon.org.

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.


Comment on Re: Using Perl XPath for converting Infopath XML files to Word Documents
Re^2: Using Perl XPath for converting Infopath XML files to Word Documents
by Anonymous Monk on Sep 22, 2005 at 09:59 UTC
    Will this scritp will also run in UNIX operating system? As I donot have any XML pareser which can be loaded for UNIX.

      Did you try?

      It will work if you have XML::XPath (and XML::Parser) installed. You also need expat, the XML parsing library, which comes installed on a lot of systems, or can be compiled from sources (just make sure you are using the same compiler you compiled Perl with)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://421956]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-10-24 16:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (133 votes), past polls