Page 1 of 1

Using collection() with XPath Builder to search across files

Posted: Fri May 22, 2009 8:46 am
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.

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

Posted: Fri May 22, 2009 9:34 am
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.

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

Posted: Fri May 22, 2009 6:29 pm
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

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

Posted: Fri May 22, 2009 6:32 pm
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

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

Posted: Mon May 25, 2009 7:05 am
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.

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

Posted: Mon May 25, 2009 12:16 pm
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