Using collection() with XPath Builder to search across files

Having trouble installing Oxygen? Got a bug to report? Post it all here.
csalsa
Posts: 97
Joined: Tue Apr 22, 2008 9:31 am

Using collection() with XPath Builder to search across files

Post by csalsa »

Hi

I am trying to use collection() in lieu of a XPath search across all files.

However, I cannot get it to recurse across directories. Do I have the meaning of 'recurse' right? Is recurse files across directories or recurse files within a directory?

For example: the statements:
Does not works:

Code: Select all

collection('file:///D:/Develop/IFW MODELLING/Samples?select=*.xml;recurse=true')//postingEntry/name
Works for files in R22:

Code: Select all

collection('file:///D:/Develop/IFW MODELLING/Samples/R22?select=*.xml;recurse=true')//postingEntry/name
I want to recurse across all subdirectories of the Samples directory.
csalsa
Posts: 97
Joined: Tue Apr 22, 2008 9:31 am

Re: Using collection() with XPath Builder to search across files

Post by csalsa »

I found that the source code does not appear to iterate files across directories:
public Object map(Item item, XPathContext context)
public File[] listFiles()

That is a shame.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Using collection() with XPath Builder to search across files

Post by sorin_ristache »

Hello,
csalsa wrote:However, I cannot get it to recurse across directories. Do I have the meaning of 'recurse' right? Is recurse files across directories or recurse files within a directory?

For example: the statements:
Does not works:

Code: Select all

collection('file:///D:/Develop/IFW MODELLING/Samples?select=*.xml;recurse=true')//postingEntry/name

The correct query parameter is recurse=yes not recurse=true.


Regards,
Sorin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Using collection() with XPath Builder to search across files

Post by sorin_ristache »

csalsa wrote:I found that the source code does not appear to iterate files across directories:
public Object map(Item item, XPathContext context)
public File[] listFiles()

That is a shame.
What source code are you talking about? The collection() function of Saxon 9 iterates a directory collection if you use the correct parameters. There is an example in the User Manual.


Regards,
Sorin
csalsa
Posts: 97
Joined: Tue Apr 22, 2008 9:31 am

Re: Using collection() with XPath Builder to search across files

Post by csalsa »

Hi Sorin

Thanks for the correction of using 'yes/no' instead of 'true/false'. I had made assumptions on the boolean variable that were obviously wrong from the sample you highlighted.

The code that I was referring to was the 'saxonb' » 'net.sf.saxon.functions' whose source code has been put up on the Internet. I obviously did not spend enough time reading the code either.


The reason that I am trying to get 'collection()' to work is that I really want to search with XPath across a set of directories. We have some 7100 XML files across 35 directories. I know an XPath search will take time. But sometimes you just need an XPath search.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Using collection() with XPath Builder to search across files

Post by sorin_ristache »

Hello,
csalsa wrote:The code that I was referring to was the 'saxonb' » 'net.sf.saxon.functions' whose source code has been put up on the Internet. I obviously did not spend enough time reading the code either.
That is Saxon 9 source code. You should ask Saxonica about it.
csalsa wrote:The reason that I am trying to get 'collection()' to work is that I really want to search with XPath across a set of directories. We have some 7100 XML files across 35 directories. I know an XPath search will take time. But sometimes you just need an XPath search.
If you use the collection() function in an XPath 2.0 query as in the User Manual example it should work. Oxygen includes Saxon 9 which executes the collection() call.


Regards,
Sorin
Post Reply