In a notification Worklight adapter - I invoke the adapter passing a very long XML string from the backend service.
The backend service cannot be altered or changed.
I want to be able to turn the javascript String object into something I can parse and use useful functions on such as :
var custNum = doc.getElementsByTagName("data:custNum")[0];
However all attempts so far at creating the 'doc' variable have failed. Standard DOMParser and window methods are undefined and out of scope in adapters. I would rather not resort to lengthy string splitting to find my nodes!
Many thanks
In the end I wrote a function like this :
Which I use - nice and simple.
Set returnedContentType: "xml". This will force WL platform to parse XML for you automatically and convert it to JSON you can manipulate.
E.g.
Will be converted to
so you can get values with syntax like response.a.b
You should use XSL Transformation Filtering to get rid of all unneeded data from the XML.
Something like this should be your adapter JavaScript function:
and something like this should be in your XSL file
Please check Getting started with IBM Worklight (http://www.ibm.com/developerworks/mobile/worklight/getting-started.html) module 5.2 - Creating HTTP Adapters(ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/Module_05_2_-_Creating_HTTP_Adapters.pdf) and its exercise and code sample(ftp://public.dhe.ibm.com/software/mobile-solutions/worklight/docs/v505/module_05_2_HTTP_Adapter.zip).