Find & Replace with XPath

Having trouble installing Oxygen? Got a bug to report? Post it all here.
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Find & Replace with XPath

Post by solarian »

I'm encountering an issue with Find & Replace when the Xpath filter is in use.

Running a "Replace All", if there are multiple "finds", it does some replaces, but then stops before completing without reporting an error. Doing the same Find & Replace with the single "Replace" option (rather than "Replace All"), after a seemingly random number of finds, it crashes with "XPath: XPath failed due to: class java.lang.NullPointerException".

It doesn't seem to make any difference whether the XPath expression evaluates to multiple nodes or not -- even if there is only one node, it still doesn't replace properly within that node. Also, it doesn't seem to matter whether regexes are being used.

XPath with regex is an excellent feature -- best of luck with the bugfix.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Find & Replace with XPath

Post by sorin_ristache »

Hello,

First you should know that the Find/Replace dialog does not match overlapping items, for example if you want to replace aa with a in the string aaaa only two matches will be reported and replaced: the group of the first two a letters and the group of the last two a letters and final the result will be aa.

For any other cases that find/replace skips some matches and for the NullPointerException please post a sample text or send a sample XML document for reproducing the error and specify the values of Text to find, Replace with and XPath. Do you get the problem in Oxygen version 10.2 (the current version) or in a previous version?


Thank you,
Sorin
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Find & Replace with XPath

Post by solarian »

Hi,

Re: aaaa and all that, I understand what you're saying and this is not the issue. What you describe is correct behaviour. I would use regex \a{2,}\ to strip that kind of stuff.

As for the problems I've encountered, I've reproduced it in a sample file which I'm now sending to you, along with further details.

Thanks,

Ian
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Find & Replace with XPath

Post by solarian »

P.S. Would you please consider setting it up so the Find/Replace box remembers the XPath expression entered, in the same way it does both the Find text and Replace text when closing and re-opening the Find/Replace dialog? Thanks.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Find & Replace with XPath

Post by sorin_ristache »

solarian wrote:As for the problems I've encountered, I've reproduced it in a sample file which I'm now sending to you, along with further details.
Thank you for the file. We fixed the bug. The fix will be available in the next version (10.3). If you want a patch for version 10.2 that fixes this bug please let us know.


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

Re: Find & Replace with XPath

Post by sorin_ristache »

solarian wrote:Would you please consider setting it up so the Find/Replace box remembers the XPath expression entered, in the same way it does both the Find text and Replace text when closing and re-opening the Find/Replace dialog? Thanks.
The XPath combo box remembers the previous expressions in the drop-down list of the combo box. When you reopen the Find/Replace dialog just click the down arrow button of the XPath combo box. For the Text to find and Replace with fields you have to do the same: click the history button near the name of the field for displaying a drop-down list with previous values.


Regards,
Sorin
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Find & Replace with XPath

Post by solarian »

Gosh, that was quick! Yes, a patch would be very helpful for me, as I'm doing a lot of Find & Replace whilst converting a large text file to TEI.

Re: re-opening the Find/Replace dialog, when I do that I get the "text to find" and "replace with" boxes already populated with my previous search (as it should), but not the XPath, where I have to use the history (as you say). This seems a little inconsistent, and it's easy to forget to re-select the previous XPath expression.

Whilst I'm on the subject, it would also be helpful if the dialog reported the number of replaced items when doing a "Replace All" -- it could be printed in the space where "String not found" is printed currently.

Thanks for the patch -- good work.
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Find & Replace with XPath

Post by sorin_ristache »

solarian wrote:Re: re-opening the Find/Replace dialog, when I do that I get the "text to find" and "replace with" boxes already populated with my previous search (as it should), but not the XPath, where I have to use the history (as you say). This seems a little inconsistent, and it's easy to forget to re-select the previous XPath expression.
I added an enhancement request to select in the XPath combo the value that was used with the current value of Text to find and Replace with.
solarian wrote:Whilst I'm on the subject, it would also be helpful if the dialog reported the number of replaced items when doing a "Replace All" -- it could be printed in the space where "String not found" is printed currently.
We have this enhancement request already logged in our system.


Regards,
Sorin
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Find & Replace with XPath

Post by solarian »

sorin wrote:I added an enhancement request to select in the XPath combo the value that was used with the current value of Text to find and Replace with.
This works fine, but for some reason when starting up Oxygen the XPath box is populated with the last used XPath expression from a previous instance of Oxygen, when the other boxes (Find/Replace) are empty. It would seem better that the XPath box should always be empty when starting Oxygen.
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Find & Replace with XPath

Post by solarian »

P.S. Again in 10.3, It seems that when one re-opens the Find/Replace box and a previous XPath expression appears in the XPath box, it nevertheless does not actually process the XPath filter unless one clicks in the XPath box before pressing "Find".
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Find & Replace with XPath

Post by sorin_ristache »

solarian wrote:This works fine, but for some reason when starting up Oxygen the XPath box is populated with the last used XPath expression from a previous instance of Oxygen, when the other boxes (Find/Replace) are empty. It would seem better that the XPath box should always be empty when starting Oxygen.
You are right. We will fix that.


Thank you for reporting it,
Sorin
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Find & Replace with XPath

Post by sorin_ristache »

solarian wrote:when one re-opens the Find/Replace box and a previous XPath expression appears in the XPath box, it nevertheless does not actually process the XPath filter unless one clicks in the XPath box before pressing "Find".
You are right, the XPath expression should be applied on the find actions triggered by the Find button regardless of clicking on the Xpath combo. We will fix that too.


Regards,
Sorin
solarian
Posts: 48
Joined: Thu Mar 12, 2009 10:27 pm

Re: Find & Replace with XPath

Post by solarian »

I assume you're aware of this, but I notice that the first problem (XPath box population on application start) has been fixed in the current installer, but the second one has not, viz.:
when one re-opens the Find/Replace box and a previous XPath expression appears in the XPath box, it nevertheless does not actually process the XPath filter unless one clicks in the XPath box before pressing "Find".
sorin_ristache
Posts: 4141
Joined: Fri Mar 28, 2003 2:12 pm

Re: Find & Replace with XPath

Post by sorin_ristache »

You are right, the second one was not fixed yet. We will fix that too in a future version.


Regards,
Sorin
ra0543
Posts: 80
Joined: Wed Jan 14, 2009 12:50 pm

Re: Find & Replace with XPath

Post by ra0543 »

Why is the XPath box in the Find/Replace dialogue usually greyed out? What do I have to do to get it to allow me to enter anything into it?
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Find & Replace with XPath

Post by adrian »

Hi,

XPath in the Find/Replace dialog is only available in Text mode if the document is XML well-formed. You can check the latter with Document -> Validate -> Check Document Form(Ctrl + Shift + W).

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
ra0543
Posts: 80
Joined: Wed Jan 14, 2009 12:50 pm

Re: Find & Replace with XPath

Post by ra0543 »

Thanks. Now I see it: it's fine in text mode as the document is well-formed.

I use Oxygen almost entirely in Author mode, because it is so much more user-friendly. Can the XPath search be made available in Author mode too? It would be really useful.
adrian
Posts: 2879
Joined: Tue May 17, 2005 4:01 pm

Re: Find & Replace with XPath

Post by adrian »

We already have this feature request on our issue tracking tool and it will be implemented in a future version of Oxygen.

Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Post Reply