Can Element Content be moved to Attribute Value location?

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

Can Element Content be moved to Attribute Value location?

Post by binar » Wed Jun 12, 2019 12:51 am

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?

adrian
Posts: 2533
Joined: Tue May 17, 2005 4:01 pm

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

Post by adrian » Thu Jun 13, 2019 5:26 pm

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
Adrian Buza
<oXygen/> XML Editor, Schema Editor and XSLT Editor/Debugger
http://www.oxygenxml.com

Post Reply