Page 1 of 1

"Find in Files" xpath

Posted: Fri Nov 03, 2006 12:31 am
by sanderson
I'm trying to figure out if any of the xml files in my project have a particular xpath (//ph/varname). Is there anyway to do this in oXygen?

Posted: Fri Nov 03, 2006 11:25 am
by sorin_ristache
Hello,

It is not possible with only one Find action. The XPath filter is available only in the Find/Replace dialog for the current editor. In the current version of <oXygen/> (7.2) you have to open every file of the project, open the Find/Replace dialog and enter your XPath expression in the XPath field of the dialog.


Regards,
Sorin

Posted: Fri Nov 03, 2006 4:32 pm
by george
There is something you can do, but in a directory rather than in the project files.
If you want to find information in a set of files then you can do that using the XPath 2.0 evaluation in oXygen that works based on Saxon 8. Saxon 8 has support for the collection function that can return all the documents in a specific directory (recursively, with filters, etc). For more details about collection parameters you can look at
http://www.saxonica.com/documentation/j ... olver.html

As an example the following XPath
collection('.?select=*.xml')//ph/varname
will list all the varname elements that have a ph parent in the XML files in the directory of the current document
collection('.?select=*.xml')/document-uri(.)
will list all the XML files in the current directory

Best Regards,
George

Posted: Mon Nov 06, 2006 10:23 pm
by sanderson
Thanks, George, that sounds like it will work perfectly for me. I'm afraid, though, that the solution is a little over my head.

If you can answer a few questions, I think I can figure this out.
  • Does that example [collection('.?select=*.xml')//ph/varname] go into an XSL stylesheet or an XML file? Do I need to add extensions to the header to make the file valid?

    How do I tell Saxon to use the StandardCollectionURIResolver with Saxon 8? Can I do it both at the command-line and in oXygen? I tried, at the command-line "-r StandardCollectionURIResolver", but Saxon reported "No URIResolver class". I also tried the full path to the class with the same result.
Thanks again, George, this is going to be a real help for me.

Steve

Posted: Tue Nov 07, 2006 9:43 am
by george
Hi Steve,

Saxon 8 is using that collection resolver by default. The examples I gave you should work in the XPath evaluator in oXygen. Try to open one of your XML files and enter the expressions in the XPath field, make sure you choose XPath 2.0 and see the results.

Best Regards,
George

Brilliant!

Posted: Wed Nov 08, 2006 9:11 pm
by sanderson
I added a bit to get it to recurse, but I used that basic idea.

Code: Select all

collection('?recurse=yes;select=*.xml')//ph/varname
did the job for me.

Doesn't work right in version 8.0

Posted: Mon Nov 20, 2006 10:35 pm
by sanderson
:(

In version 8.0, the results are all listed as if they were in the active file, so you can't click into them.

Posted: Tue Nov 21, 2006 11:22 am
by george
There were some changes in the XPath evaluation to locate better the results. In 8.0 the exact location of an element is presented while in previous versions only the line was highlighted. It seems that this change affected the results obtained through collection. We recorded this problem and we will look into that.

Best Regards,
George

Posted: Tue Nov 21, 2006 4:18 pm
by Dan
We fixed the problem.

You can find a new oxygen jar file here:

http://www.oxygenxml.com/update/oxygenXPath.jar

You can replace the oxygen.jar file from the lib directory of your standalone installation with this file.
Let us know if it worked.

Thank you,
Dan

Great fix, thanks.

Posted: Tue Nov 21, 2006 8:23 pm
by sanderson
I renamed oxygen.jar to oxygen.bak, dropped this file in and renamed it to oxygen.jar, and it worked great. Thanks for the quick turn-around!

Broken in v10 (Re: "Find in Files" xpath)

Posted: Wed Nov 19, 2008 8:12 pm
by sanderson
When I try this solution now, I get an error message
XPath failed eud to: collection catalogue must contain top-level element <collection>
Any tips on how to get this back? I know I can use an xquery file to do the same thing, but this is just so handy for me that I'll really miss it if I lose this functionality.

Re: "Find in Files" xpath

Posted: Thu Nov 20, 2008 11:24 am
by sorin_ristache
Hello,

Look at the description of the URI resolver. If your URI does not start with "file:/" or does not reference a directory then the resolver reads the file as a collection catalog, that is an XML file with a <collection> root element. If the root element is not <collection> you get the error.


Regards,
Sorin

Re: "Find in Files" xpath

Posted: Fri Nov 21, 2008 12:23 am
by sanderson

Code: Select all

collection('?recurse=yes;select=file:///C:/dev/doc/156/patch/core/ja/xmlsource/dev_guides/apex/classes/')//ph/varname
Fails with the same error, too. As does file:/C:..., file://C:...

Changing the forward slashes into back-slashes results in an invalid URI error.

Re: "Find in Files" xpath

Posted: Fri Nov 21, 2008 1:13 pm
by sorin_ristache
You did not specify the collection. I think you should use something like:

Code: Select all

collection('file:///C:/dev/doc/156/patch/core/ja/xmlsource/dev_guides/apex/classes?recurse=yes;select=*.xml')//ph/varname
You can use your own file filter instead of *.xml in select=*.xml.


Regards,
Sorin

Re: "Find in Files" xpath

Posted: Tue Nov 25, 2008 12:24 am
by sanderson
That did the trick. Thanks.