Global XML Attribute Change Possible?

Questions about XML that are not covered by the other forums should go here.
binar
Posts: 26
Joined: Wed Apr 10, 2019 7:43 pm

Global XML Attribute Change Possible?

Post by binar »

Greetings,
Is it possible for OxygenXML to perform the following find and replace operation so it can save me a lot of time. I have 1,450 XML files. I need OxygenXML to globally look for the "colwidth" attribute through all 1,450 XML files. Two colwidth attribute examples I need to globally edit are shown below:

Example #1:

Code: Select all

colwidth="0.83*"  (not missing * character)
Example #2:

Code: Select all

colwidth="155.7"  (missing * character)
For all colwidth attributes missing an asterik symbol

Code: Select all

*
as shown in Example #2 I need OxygenXML to add the

Code: Select all

*
as shown in Example #1. If the colwidth attribute already has the

Code: Select all

*
included I need OxygenXML to skip the attribute change.

Is such an attribute find & replace operation possible to execute in OxygenXML? Any help will be greatly appreciated. Thanks in advance.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Global XML Attribute Change Possible?

Post by Radu »

Hi,
Go to the main menu Tools->XML Refactoring, choose "Replace in Attribute Value".
In the dialog set the "Element" field to *[@colwidth], the "Attribute" field to colwidth, the "Find" field to (.*)[^*]$ and the "Replace" field to $1*
You can select a working set (apply on the entire project files for example) and you also have a "Preview" to check if things are working as expected.

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
binar
Posts: 26
Joined: Wed Apr 10, 2019 7:43 pm

Re: Global XML Attribute Change Possible?

Post by binar »

Hi Radu,
Thank you very much for your post. I am amazed with this OxygenXML capability I did not know was included in the software. I followed your instructions and did a PREVIEW. Below are a couple examples of the results I am getting:

Before Change:

Code: Select all

colwidth="98.45"

Code: Select all

colwidth="108.45"
After Change Preview:

Code: Select all

colwidth="98.4*"

Code: Select all

colwidth="108.4*"
As you can see from the before and after examples above, OxygenXML is removing the "5" and replacing it with the asterik symbol

Code: Select all

*
How can we change the find and replace values below:

Find = (.*)[^*]$
Replace = $1*

so that the number "5" remains and I get the result shown below?

Code: Select all

colwidth="98.45*"

Code: Select all

colwidth="108.45*"
Thank you for your help with this matter.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Global XML Attribute Change Possible?

Post by Radu »

Hi,

You can try to find something like (.*)([^*])$ and replace with $1$2*

Regards,
Radu
Radu Coravu
<oXygen/> XML Editor
http://www.oxygenxml.com
binar
Posts: 26
Joined: Wed Apr 10, 2019 7:43 pm

Re: Global XML Attribute Change Possible?

Post by binar »

Greeting Radu,
I have a followup question regarding the coding you previously posted shown below:

Code: Select all

(.*)([^*])$ 
$1$2*
OR
(.*)[^*]$
$1*
What name does this coding have? Is it a Regular Expression or Perl Expression or something else entirely? I ask because I have another attribute change to make using the Find & Replace fields located in "Tools->XML Refactoring, choose "Replace in Attribute Value". Below is the problem summarized.

The "item" attribute below is not validating because it needs a leading zero added in front of all two digit numbers.

Code: Select all

item = "12"   (This is the wrong format and does not validate)

Code: Select all

item = "012"   (This is the correct format and validates)
In short, please help me with a find & replace code that will skip over "item" attribute values already setup with three digits. But will automatically add a leading zero to all "item" attribute values only setup with two digits.

Over the weekend I Googled this matter to see if I could find a solution. The links below shows two online testers I referred to in an effort to develop my own Find & Replace code but was not successful:

https://www.infobyip.com/regularexpress ... ulator.php

https://ingram-braun.net/public/program ... le-regexp/

In your opinion what is the best online tester to use that is compatible with XML Refactoring find & replace fields? Also I was not able to find any OxygenXML Editor documentation that provides an overview of how to write your own Find & Replace code to change Attributes.

Lastly, it would be great if a future version of OxygenXML editor included its own find & replace code tester designed to remove some of the complexity involved with this task.

Thanks for your help with this matter.
Radu
Posts: 9018
Joined: Fri Jul 09, 2004 5:18 pm

Re: Global XML Attribute Change Possible?

Post by Radu »

Hi,

These constructs are regular expressions implemented in Java based closely on PERL based expressions.
They should work and can also be tested in the Oxygen Find/Replace dialog:
https://www.oxygenxml.com/doc/versions/ ... sions.html

In your case you should probably search for ^(\d\d)$ and replace with 0$1.

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