Delete node/element but not its child
Posted: Wed Dec 05, 2012 5:03 pm
I need to delete certain nodes in an xml document without deleting their childs.
Here a simplified sample. In this example I want to delete all span elements that have a img child (somewhere).
Before:
After:
I can regex search for .* with xpath //span[descendant::*/img] but i will always also delete all childs of the node found. And that's exactly what I now want to do.
That is, basically it should work like placing the cursor in a span tag and select Refactoring - Delete Element Tags (Alt-Shift-X).
How can I do this (without XSLT)?
(Samples are for demonstration purposes only not the actual code.)
Here a simplified sample. In this example I want to delete all span elements that have a img child (somewhere).
Before:
Code: Select all
<body>
<p><span><img src="test.png"/></span></p>
<p><span class="foo"><img src="test.png"/></span></p>
<p><span class="test"><b><img src="test.png"/></b></span></p>
<p><span class="test"><b><i><img src="test.png"/></i></b></span></p>
<p>Please open menu <span class="uistring">File</span> and select ...</p>
</body>
Code: Select all
<body>
<p><img src="test.png"/></p>
<p><img src="test.png"/></p>
<p><b><img src="test.png"/></b></p>
<p><b><i><img src="test.png"/></i></b></p>
<p>Please open menu <span class="uistring">File</span> and select ...</p>
</body>
That is, basically it should work like placing the cursor in a span tag and select Refactoring - Delete Element Tags (Alt-Shift-X).
How can I do this (without XSLT)?
(Samples are for demonstration purposes only not the actual code.)