Page 1 of 1

Can Element Content be moved to Attribute Value location?

Posted: Wed Jun 12, 2019 12:51 am
by binar
Greetings,
Can XML Factoring perform the following operation summarized in the code examples shown below:

Example #1 - Before XML Factoring Operation:

Code: Select all

<procurementData>
<enterpriseRef>00NS2</enterpriseRef>
</procurementData>
Example #2 - After XML Factoring Operation:

Code: Select all

<procurementData>
<enterpriseRef manufacturerCodeValue="00NS2"></enterpriseRef>
</procurementData>
In Example #1 the element content shown as "00NS2" needs to move out of where it is located and take the place of the value for the attribute named "manufacturerCodeValue" as shown in Example #2. The "manufacturerCodeValue" attribute needs to be created before this move takes place. Additionally, the content in the <enterpriseRef> element has no set quantity of characters. It can be 3, 5, 8, 11 characters that need to be moved over to the "manufacturerCodeValue" attribute value location. In other words, X amount of numbers and digits need to be moved over to the value location of the "manufacturerCodeValue" attribute. Is such an operation possible?

Re: Can Element Content be moved to Attribute Value location?

Posted: Thu Jun 13, 2019 5:26 pm
by adrian
Hello,

There is no such refactoring operation available at this time (extract text node and use it as attribute value).

I guess you can use the "good old fashioned" regular expression from the Find/Replace tool.

Search for:
<enterpriseRef>(.*)</enterpriseRef>
Replace with:
<enterpriseRef manufacturerCodeValue="$1"></enterpriseRef>
[x] Regular expression
If you'd like to limit the location from the XML where this acts, you can additionally specify an XPath expression. e.g.
//procurementData/enterpriseRef

If you use Find/Replace in Files to apply this on multiple files, I recommend using Preview first. Also, it's always a good idea to have a backup copy of the files.

Regards,
Adrian