JSON to xml code

Hi There,
I have the following example XML code:

 <?xml version="1.0" encoding="UTF-8"?> 
<RequestCall>     
     <RequestName>TestDBUser.Insert</RequestName>
     <Params>         
<TestDBUser>             
 <ExtUserID>33333</ExtUserID>
 <FirstName>Peter</FirstName>             
 <LastName>NodeRed</LastName>             
 <Title>Mr</Title> 
 <UserExpiration.Enabled> 1 </UserExpiration.Enabled> 
 <UserExpiration> 2025-01-31 </UserExpiration> 
 <KeyExpirationDifferentFromUserExpiration> 1 </KeyExpirationDifferentFromUserExpiration> 
 <KeyRevalidation.UpdatePeriod> 3 </KeyRevalidation.UpdatePeriod> 
 <KeyRevalidation.UnitOfUpdatePeriod>0</KeyRevalidation.UnitOfUpdatePeriod>         
     </TestDBUser>
   </Params> 
</RequestCall>

image

If I insert it in an inject node msg.payload and send it through the HTTP Request node, it works fine and creates the user in my 3rd Party system.
But I will receive the name from an other system in JSON in a msg.username payload. How Can I insert this username into my xml code to make the First and LastName dynamic?

There are multiple ways, but let's take an example inject node

Next use a template node:

there you can use 'mustache' templates, so you can create a base template in xml and fill whatever details you want.

 <FirstName>{{payload.firstname}}</FirstName>             
 <LastName>{{payload.lastname}}</LastName>            

Output:

<?xml version="1.0" encoding="UTF-8"?> 
<RequestCall>     
     <RequestName>TestDBUser.Insert</RequestName>
     <Params>         
<TestDBUser>             
 <ExtUserID>33333</ExtUserID>
 <FirstName>John</FirstName>             
 <LastName>Doe</LastName>             
 <Title>Mr</Title> 
 <UserExpiration.Enabled> 1 </UserExpiration.Enabled> 
 <UserExpiration> 2025-01-31 </UserExpiration> 
 <KeyExpirationDifferentFromUserExpiration> 1 </KeyExpirationDifferentFromUserExpiration> 
 <KeyRevalidation.UpdatePeriod> 3 </KeyRevalidation.UpdatePeriod> 
 <KeyRevalidation.UnitOfUpdatePeriod>0</KeyRevalidation.UnitOfUpdatePeriod>         
     </TestDBUser>
   </Params> 
</RequestCall>
1 Like

WOW, i did not think about this, I over killed it .
Thank you very much!!!

1 Like