Automatically remove empty attributes

Having trouble installing <oXygen/>? Got a bug to report? Post it all here.
Posts: 1

Automatically remove empty attributes

Thu Sep 28, 2017 5:44 am

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"?>
    <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 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 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 = "" video = "" audio = "" era = "">

Thanks in advance for any help!

Posts: 5811

Re: Automatically remove empty attributes

Thu Sep 28, 2017 8:17 am

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.

Radu Coravu
<oXygen/> XML Editor

Return to “Common Problems”

Who is online

Users browsing this forum: No registered users and 2 guests