How to delete items having nodes containing numbers
Questions about XML that are not covered by the other forums should go here.
-
- Posts: 2
- Joined: Mon Mar 13, 2017 1:01 pm
How to delete items having nodes containing numbers
Hi,
I love the software however I have a problem regarding a XML file.
The XML structure looks like this:
<PRODUCTS>
<PRODUCT>
<ID><![CDATA[1]]</ID>
<NAME>TEST</NAME>
</PRODUCT>
<PRODUCT>
<ID><![CDATA[ABC1]]</ID>
<NAME>Test with letters</NAME>
</PRODUCT>
</PRODOUCTS>
How can I search and delete all products with numbers only? Also I would like to know if it's possible to wrap nodes? Lets say I want to wrap all NAME nodes inside my PRODUCT with <INFO></INFO>
I love the software however I have a problem regarding a XML file.
The XML structure looks like this:
<PRODUCTS>
<PRODUCT>
<ID><![CDATA[1]]</ID>
<NAME>TEST</NAME>
</PRODUCT>
<PRODUCT>
<ID><![CDATA[ABC1]]</ID>
<NAME>Test with letters</NAME>
</PRODUCT>
</PRODOUCTS>
How can I search and delete all products with numbers only? Also I would like to know if it's possible to wrap nodes? Lets say I want to wrap all NAME nodes inside my PRODUCT with <INFO></INFO>
-
- Posts: 2879
- Joined: Tue May 17, 2005 4:01 pm
Re: How to delete items having nodes containing numbers
Hi,
I'd recommend Find/Replace for this one. It's also possible with "XML Refactoring" (Elements > Delete Element, same XPath), but you'll lose the CDATA tags (not the data itself but the tags surrounding it).
Open Find > Find/Replace:
Find: (?s).*
Replace with: (leave empty)
XPath: //PRODUCT[matches(ID/text(), "^\d+$")]
[x] Regular expression
Press "Replace All".
Open Find > Find/Replace:
Find: (?s).*
Replace with: <INFO>$0</INFO>
XPath: //NAME[ancestor::PRODUCT]
[x] Regular expression
Press "Replace All".
Note: XPath only works if your XML file is well-formed. Check for that with menu > Document > Validate > Check Well-Formedness.
Regards,
Adrian
I'm guessing you mean all products with numeric IDs.How can I search and delete all products with numbers only?
I'd recommend Find/Replace for this one. It's also possible with "XML Refactoring" (Elements > Delete Element, same XPath), but you'll lose the CDATA tags (not the data itself but the tags surrounding it).
Open Find > Find/Replace:
Find: (?s).*
Replace with: (leave empty)
XPath: //PRODUCT[matches(ID/text(), "^\d+$")]
[x] Regular expression
Press "Replace All".
Normally you'd do this with XML Refactoring (Elements > Wrap element, XPath), but since that affects CDATA, we'll use Find/Replace again:Also I would like to know if it's possible to wrap nodes? Lets say I want to wrap all NAME nodes inside my PRODUCT with <INFO></INFO>
Open Find > Find/Replace:
Find: (?s).*
Replace with: <INFO>$0</INFO>
XPath: //NAME[ancestor::PRODUCT]
[x] Regular expression
Press "Replace All".
Note: XPath only works if your XML file is well-formed. Check for that with menu > Document > Validate > Check Well-Formedness.
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