Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

How to modify XML request payload using Javascript?

pxzxz1
New Member

Hello Apigeeks,

1. How do I update value in XML that comes from request payload?

2. How do I insert new element to the XML that comes from request payload?

For both items mentioned above, I tried with Javascript object model

var name = context.targetRequest.body.asXML.name;
request.content.asXML
context.proxyRequest.content.asXML

Unfortunately, these does not help me to do what I want. Basically,

1. I want to modify a value in XML, say <amount>0</amount> update to <amount>200</amount>

2. I want to add new element to the XML, say <student><name>Thomson</name></student> to <student><id>xx123</id><name>Thomson</name></student>

Not sure if it's matter, but it is a SOAP XML.

Solved Solved
0 12 4,829
1 ACCEPTED SOLUTION

Patricia,

It does not work for update (that does not involves adding new namespace)

What do you mean? It works for me, with the example payload you provided.

The JS error happens because your JavaScript tool does not recognize the e4x extensions. There's no error in the JS that I gave you.

Attached please find a working example.

apiproxy-e4x-update.zip

View solution in original post

12 REPLIES 12
Top Solution Authors