I'm using apigee to generate responses that match with the CMIS specification, and I have some XML that contains colons:
<atom:title>c9ad76c6-d121-4a32-bb14-e5d43bf91ee6</atom:title>
Obviously the
var r = response.content.asXML;
r.atom:title = "lala";
doesn't work. How do I set the content asXML to support colons on tags?
Thanks!
Solved! Go to Solution.
You can try something like the following example(based on using e4x with Rhino):
Example payload:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>Invalid ApiKey</faultstring> <faultactor /> <detail> <source> <errorcode>oauth.v2.InvalidApiKey</errorcode> </source> </detail> </soap:Fault> </soap:Body> </soap:Envelope>
Example JS code to work with this xml where 'soap' is the namespace:
var xmlObj = response.content.asXML // or new XML (response.content); var soap = new Namespace('http://schemas.xmlsoap.org/soap/envelope/'); if(xmlObj.soap::Body !== undefined && xmlObj.soap::Body !== null){ var faultstring = xmlObj.soap::Body.soap::Fault.faultstring.toString(); var errorcode = xmlObj.soap::Body.soap::Fault.detail.source.errorcode.toString(); } context.setVariable('message.header.x-faultstring', faultstring); context.setVariable('message.header.x-errorcode', errorcode);
You can try something like the following example(based on using e4x with Rhino):
Example payload:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" soap:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"> <soap:Body> <soap:Fault> <faultcode>soap:Server</faultcode> <faultstring>Invalid ApiKey</faultstring> <faultactor /> <detail> <source> <errorcode>oauth.v2.InvalidApiKey</errorcode> </source> </detail> </soap:Fault> </soap:Body> </soap:Envelope>
Example JS code to work with this xml where 'soap' is the namespace:
var xmlObj = response.content.asXML // or new XML (response.content); var soap = new Namespace('http://schemas.xmlsoap.org/soap/envelope/'); if(xmlObj.soap::Body !== undefined && xmlObj.soap::Body !== null){ var faultstring = xmlObj.soap::Body.soap::Fault.faultstring.toString(); var errorcode = xmlObj.soap::Body.soap::Fault.detail.source.errorcode.toString(); } context.setVariable('message.header.x-faultstring', faultstring); context.setVariable('message.header.x-errorcode', errorcode);
Hi Russo, i'm trying to read the request xml, format is below <?xml version="1.0" encoding="UTF-8"?> <S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/"> <S:Body> <login xmlns="urn:xxobject.xxx.xxxx.com" xmlns:ns2="urn:fault.xxx.xxxx.com"> <credential> <cId>1234</cId> <username>user</username> <password>pass</password> </credential> <param> <name>batchSize</name> <value>200</value> </param> </login> </S:Body> </S:Envelope> i would like to access element <cId>1234</cId> in above xml, could you let me know how to achieve it in javascript of apigee. i tried below options, however it didn't work option:1 var xmlObj = request.content.asXML; var S = new Namespace('http://schemas.xmlsoap.org/soap/envelope/'); var value = xmlObj.S::Body.credential.cId.toString(); context.setVariable("value1",context.getVariable('value')); option-2 var xmlObj = request.content.asXML; var S = new Namespace('http://schemas.xmlsoap.org/soap/envelope/'); var l= new Namespace ('urn:xxobject.sxxx.xxxx.com'); var value = xmlObj.S::Body.l::credential.companyId.toString(); context.setVariable("value1",context.getVariable('value')); Regards, Ch.Venkat
Hi Venkat,
please don't ask new questions in comments attached to old answers. Post new questions with the "ask a question" button.
It should be something like this:
var S = new Namespace('http://schemas.xmlsoap.org/soap/envelope/');
var L= new Namespace ('urn:xxobject.sxxx.xxxx.com');
var value = xmlObj.S::Body.L::login.L::credential.L::cId.toString();
User | Count |
---|---|
3 | |
2 | |
1 | |
1 | |
1 |