Author |
Message
|
Gemz |
Posted: Mon Feb 18, 2013 6:16 am Post subject: Rename an XML element |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
Hi,
I have an XML in which I want to change few XML Element names.
I can do that using SET statement from Input to Output.
Consider below XML
Code: |
<root>
<header>
<msgid>123-21321-231</msgid>
<date>201300101</date>
</header>
<payload>
<customer>
<firstname>john</firstname>
<lastname>smith</lastname>
<address>123</address>
<accounts>
<firstaccount>
<accnumber>123423</accnumber>
<!--few more details-->
</firstaccount>
<secondaccount>
<accnumber>4322132</accnumber>
<!--few more details-->
</secondaccount>
</accounts>
</customer>
<!--Customer repeats-->
</payload>
</root> |
Code: |
1. SET OutputRoot = InputRoot.
2. SET OutputRoot.XMLNSC.root.payload.customer.accounts = NULL
3. SET OutputRoot.XMLNSC.root.payload.customer.accounts.account from input again |
Now I would like to change firstaccount and secondaccount tag names to account without deleting accounts segment or any other elements.
To put is very simple, is there any function/way to rename an XML element (obviously in Output Tree) _________________ GemZ
"An expert is one who knows more and more about less and less until he knows absolutely everything about nothing...." |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Feb 18, 2013 6:30 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
FIELDNAME?
SET ... NAME .... |
|
Back to top |
|
 |
Gemz |
Posted: Mon Feb 18, 2013 7:03 am Post subject: |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
Hi mqjeff,
FIELDNAME function provides the name of the elements.
If we are using Reference variable, then we can use this function to check the name of element to which Ref variable is referring.
If I use SET statement (SET OutputRoot.*[<].A.B = SomeRef ) then it will simply create the new element with its value.
I dont want to create new element. I just want to rename an element in Output Tree. _________________ GemZ
"An expert is one who knows more and more about less and less until he knows absolutely everything about nothing...." |
|
Back to top |
|
 |
Vitor |
Posted: Mon Feb 18, 2013 7:11 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Gemz wrote: |
I dont want to create new element. I just want to rename an element in Output Tree. |
Explain to me the difference between renaming an element, and creating a new element with the correct name then deleting the old one.
References used to simply and increase efficientcy obviously. _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
kimbert |
Posted: Mon Feb 18, 2013 7:17 am Post subject: |
|
|
 Jedi Council
Joined: 29 Jul 2003 Posts: 5542 Location: Southampton
|
Quote: |
To put is very simple, is there any function/way to rename an XML element (obviously in Output Tree) |
You are asking the wrong question.
You should be asking 'how can I rename an element in the message tree'.
The names and values of elements in the message tree are processed in the same way, regardless of whether they are XML elements, JSON elements, MIME elements or any other data format.
You change the name of any syntax element in the message tree like this:
Code: |
SET myPathReference NAME = 'theNewName'; |
...and obviously, myPathReference does not have to be a REFERENCE variable - it can be a normal path pointing to a part of the message tree. |
|
Back to top |
|
 |
Gemz |
Posted: Mon Feb 18, 2013 7:41 am Post subject: |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
Hi Vitor,
Quote: |
Explain to me the difference between renaming an element, and creating a new element with the correct name then deleting the old one. |
Both are almost same, but when we delete and copy to a new element we might need to consider atleast a bit that we did not miss any data.
Instead if we just rename, we are sure we dont miss any data.
Kimbert,
Quote: |
To put is very simple, is there any function/way to rename an XML element (obviously in Output Tree)
You are asking the wrong question.
You should be asking 'how can I rename an element in the message tree' |
Thanks Kimbert, I got your point... _________________ GemZ
"An expert is one who knows more and more about less and less until he knows absolutely everything about nothing...." |
|
Back to top |
|
 |
Vitor |
Posted: Mon Feb 18, 2013 7:46 am Post subject: |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
Gemz wrote: |
Both are almost same, but when we delete and copy to a new element we might need to consider atleast a bit that we did not miss any data.Instead if we just rename, we are sure we dont miss any data. |
I would accept your point if you did a delete and copy. What about if you do a copy and delete (i.e. the other order). _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
mqjeff |
Posted: Mon Feb 18, 2013 7:48 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
Vitor wrote: |
Gemz wrote: |
Both are almost same, but when we delete and copy to a new element we might need to consider atleast a bit that we did not miss any data.Instead if we just rename, we are sure we dont miss any data. |
I would accept your point if you did a delete and copy. What about if you do a copy and delete (i.e. the other order). |
again, it doesn't really matter.
You can
Code: |
SET Outputroot.....MyOldField = InputRoot....MyOldField; |
And then
Code: |
Set OutputRoot.......MyOldField NAME = MyNewFieldName; |
No "delete" required. |
|
Back to top |
|
 |
Gemz |
Posted: Mon Feb 18, 2013 8:33 am Post subject: |
|
|
 Centurion
Joined: 14 Jan 2008 Posts: 124
|
Thanks, mqjeff
Hi Vitor,
I agree your point but Copy & Delete or Delete & Copy are like Recycle.
Renaming is just like Reuse which I prefer  _________________ GemZ
"An expert is one who knows more and more about less and less until he knows absolutely everything about nothing...." |
|
Back to top |
|
 |
|