Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
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

Replies are listed 'Best First'.
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?
[marto]: Wolfsbane , now I'm having flashbacks
[choroba]: Isn't Using PerlPod Creatively rather a meditation?
[choroba]: I don't see a question
[1nickt]: ugh, I stuck my head in the bass bin for 30 seconds on a dare at Ted Nugent at Hammersmith Odeon. Yes, I am 40% deaf now.
[johngg]: My daughter is incredibly jealous of my wife who got to see The Clash at Brixton many years ago. They went to see The Vaccines there recently.
[1nickt]: But the bands are even louder! I saw Spearhead (Michael Franti) at an outdoor show and had to walk a mile away to not feel pain in my chest! Babies were crying ... I asked the sound engineer why it was necessary to have the bass so loud and he laughed...
[Discipulus]: but the best i attended live was Mano Negra Patchanka at Forte Prenestino .. in 1990

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (11)
As of 2017-03-24 12:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Should Pluto Get Its Planethood Back?



    Results (301 votes). Check out past polls.