How can I reference text() nodes in the built-in "Delete element" refactoring operation?

Questions about XML that are not covered by the other forums should go here.
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

How can I reference text() nodes in the built-in "Delete element" refactoring operation?

Post by chrispitude »

I would like to use Oxygen's built-in Elements > Delete element refactoring operation to delete text() nodes in <p> elements.

Given some XML like

Code: Select all

<p>See <xref .../> for more information.</p>
I would like to delete the text and leave the <xref>:

Code: Select all

<p><xref .../></p>
However, when I try XPath expressions such as

Code: Select all

p/text()
p/self::text()
the refactoring operation tells me "Could not find any resources that would be affected by this operation." I also found that if I tried to delete every node() in <p> elements:

Code: Select all

p/node()
then it would delete named elements but leave the text() nodes:

Code: Select all

<p>See  for more information.</p>
Somehow the text() nodes are invincible to the Elements > Delete element refactoring operation. Is there a trick to referencing them from the XPath expression textbox?
Radu
Posts: 9059
Joined: Fri Jul 09, 2004 5:18 pm

Re: How can I reference text() nodes in the built-in "Delete element" refactoring operation?

Post by Radu »

Hi Chris,

The "Delete element" refactoring operation does what it says, it matches and deletes only XML elements.
It's implemented with XQuery update, the script is located in "OXYGEN_INSTALL_DIR/refactoring/delete-element.xq".
I'm not sure if we should create another predefined refactoring action for deleting text, it does not look like a very frequent use case.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
chrispitude
Posts: 907
Joined: Thu May 02, 2019 2:32 pm

Re: How can I reference text() nodes in the built-in "Delete element" refactoring operation?

Post by chrispitude »

Hi Radu,

Ahh, that makes sense! The refactoring operation is fine as-is, I just got confused because other XPath-like things worked in the pattern.

Here is the reason I asked the question:

topic23614.html: Deleting everything except cross-reference structure from a book
Post Reply