Delete node/element but not its child
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 7
- Joined: Wed Aug 31, 2011 4:03 pm
Delete node/element but not its child
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.)
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: Delete node/element but not its child
Hi,
Apologies for the late reply.
You can accomplish this in the Find/Replace dialog from Oxygen with the following:
Text to find: <span.*?>(.*?)</span>
Replace with: $1
XPath: //span[descendant-or-self::img]
Regular expression
Dot matches all (if the span element spreads to multiple lines)
Regards,
Adrian
Apologies for the late reply.
You can accomplish this in the Find/Replace dialog from Oxygen with the following:
Text to find: <span.*?>(.*?)</span>
Replace with: $1
XPath: //span[descendant-or-self::img]
Regular expression
Dot matches all (if the span element spreads to multiple lines)
Regards,
Adrian
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com
Return to “General XML Questions”
Jump to
- Oxygen XML Editor/Author/Developer
- ↳ Feature Request
- ↳ Common Problems
- ↳ DITA (Editing and Publishing DITA Content)
- ↳ SDK-API, Frameworks - Document Types
- ↳ DocBook
- ↳ TEI
- ↳ XHTML
- ↳ Other Issues
- Oxygen XML Web Author
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Content Fusion
- ↳ Feature Request
- ↳ Common Problems
- Oxygen JSON Editor
- ↳ Feature Request
- ↳ Common Problems
- Oxygen PDF Chemistry
- ↳ Feature Request
- ↳ Common Problems
- Oxygen Feedback
- ↳ Feature Request
- ↳ Common Problems
- Oxygen XML WebHelp
- ↳ Feature Request
- ↳ Common Problems
- XML
- ↳ General XML Questions
- ↳ XSLT and FOP
- ↳ XML Schemas
- ↳ XQuery
- NVDL
- ↳ General NVDL Issues
- ↳ oNVDL Related Issues
- XML Services Market
- ↳ Offer a Service