catfood has asked for the wisdom of the Perl Monks concerning the following question:

I need to open a second file using the XML::XPATH library but the documation at CPAN says "It is very much recommended that you use only 1 XPath object throughout the life of your application. This is because the object (and it's sub-objects) maintain certain bits of state information that will be useful (such as XPath variables) to later calls to find()." How to I close the first file and open a second, they are both in the same scope ? Note I am using $xp = XML::XPath->new(filename => $dirname.'/'.$file); to open the file - C

Replies are listed 'Best First'.
Re: XML::XPATH opening 2 files
by hossman (Prior) on Apr 19, 2004 at 04:26 UTC

    DISCLAIMER: I have no experience with XML::XPath, the following comment is based purely on my reading of the XML::XPath docs.

    I think maybe that statement in the docs is a little over zealous. I believe the suggest is being made with the intent being that you shouldn't construct a new XML::XPath object on the same file/data over and over each time you want to "find" something new -- that instead you should make one XPath object for each XML datasource, and use it over and over.

    If you have two seperate xml files, then it seems like you should definitely have two seperate XML::XPath objects.