Automatically remove empty attributes

Having trouble installing Oxygen? Got a bug to report? Post it all here.
jfowler
Posts: 1
Joined: Thu Sep 28, 2017 5:36 am

Automatically remove empty attributes

Post by jfowler »

Hi all.

I was curious if OxygenXML has a way to automatically remove empty attributes from a file.

For example, in the file below, the attributes for month, day, image, video, audio, and era are sometimes empty. Is there an efficient way to find and remove those?

Code: Select all


<?xml version="1.0" encoding="UTF-8"?>
<timeline>
<date title = "Billy Sunday born" year = "1862" month = "11" day = "9" notes = "William Ashley “Billy” Sunday was born to William and Mary Jane Sunday near Ames, Iowa. Five weeks later, the elder Sunday would die of pneumonia in Missouri while serving as a private in with Iowa’s Twenty-Third Volunteer Infantry Division." category = "fundamentalism" image = "" video = "" audio = "" era = "">
</date>
<date title = "Billy Sunday placed in orphanage" year = "1872" month = "" day = "" notes = "Billy Sunday’s mother placed him and his brother Ed in an orphanage due to the impoverished nature of their lives." category = "fundamentalism" image = "" video = "" audio = "" era = "">
</date>
<date title = "Billy Sunday begins playing professional baseball" year = "1883" month = "" day = "" notes = "Adrian Anson, manager of the Chicago White Stockings, recruited Billy Sunday to play for the team. He would continue to play in Chicago until 1887." category = "fundamentalism" image = "https://sabr.org/sites/default/files/images/AnsonCap-BBHOF.jpg" video = "" audio = "" era = "">
</date>
</timeline>
Thanks in advance for any help!

--Jason
Radu
Posts: 9041
Joined: Fri Jul 09, 2004 5:18 pm

Re: Automatically remove empty attributes

Post by Radu »

Hi Jason,

Oxygen's Find/Replace dialog has a checkbox which enables support for regular expressions.
For example you can search using this regexp (\s)+[^=]*="".
If you want to do things XML aware, you can right click the XML, choose in the contextual menu Refactoring->Attributes->Delete attribute.
For the element name XPath you can set * and for the attribute XPath you can set @*[.=""]. There is preview functionality which you should use to double check before performing the changes.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
Post Reply