"Find in Files" xpath

Oxygen general issues.
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

"Find in Files" xpath

Post 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?
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Post 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
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
George Cristian Bina
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

Post 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
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
George Cristian Bina
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

Brilliant!

Post 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.
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

Doesn't work right in version 8.0

Post 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.
george
Site Admin
Posts: 2095
Joined: Thu Jan 09, 2003 2:58 pm

Post 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
George Cristian Bina
Dan
Posts: 501
Joined: Mon Feb 03, 2003 10:56 am

Post 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
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

Great fix, thanks.

Post 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!
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

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

Post 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.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: "Find in Files" xpath

Post 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
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

Re: "Find in Files" xpath

Post 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.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: "Find in Files" xpath

Post 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
sanderson
Posts: 51
Joined: Fri Jan 27, 2006 12:51 am

Re: "Find in Files" xpath

Post by sanderson »

That did the trick. Thanks.
Post Reply