XML parsing using Nintex

You access a web service to get some detail and end up with a big xml variable with multiple nodes. How do you get the exact node’s value. Let’s figure out.

Step 1 – Call Web service

I call the web service Lists.asmx and use the web method GetList. Pass the listname (here Expenses2) as parameter and run the web service now.

Nintex1

Copy this xml and keep it saved, may be in a text file. (You’ll need it a couple of times)

Nintex3

Also, save the result of this web service in a workflow variable WFVXML and log it in history list.

Nintex2

Step 2 – Query XML

Now to parse this xml output, use the action Query XML as configured below

XML Source – XML

XML – Copy the xml from text file and paste it here.

Nintex4

Click XPath builder as marked above. You see a XPath Query Builder window. Click on tree view

Nintex5

Expand the node and select your required node. For instance, let’s select ID. Select and apply

Nintex6

It generates the below XPath in QueryXML action. /soap:Envelope/soap:Body/defaultNS:GetListResponse/defaultNS:GetListResult/defaultNS:List/@ID

Nintex7

Now go back to the top in this action – Query XML and delete all the xml output that you had pasted from the text file. Instead, insert reference and add the workflow variable WFVXML that you used to save the xml output from the previous action – Call Web Service (Remember, you saved the output in WFVXML).

Nintex8

Save the id in a workflow variable WFVId and log it in the history list.

Nintex9

And you’re done. Below is a snap shot of all the actions

Nintex10

Show Stopper

Okay… hold on…
Even though all actions are configured and the workflow is published, ready to run, we may face a hindrance. So to avoid that, let’s disable the last two actions for once i.e. Query XML & Log in History List – Id. Once disabled, republish the workflow and run it. On completion you may see the XML output logged as below

<List DocTemplateUrl=”/support/IT/AIX/Expenses2/Forms/template.xsn” DefaultViewUrl=”/support/IT/AIX/Expenses2/Forms/AllItems.aspx” MobileDefaultViewUrl=”” ID=”{1FD5DF1D-A70E-49B2-88FE-6C361E571692}” Title=”Expenses2″ Description=”” ImageUrl=”/_layouts/ima…..

If you compare it with the actual output that you stored in your text file, you’ll see the difference. The actual output is something like this –

<soap:Envelope xmlns:soap=”http://schemas.xmlsoap.org/soap/envelope/&#8221; xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance&#8221; xmlns:xsd=”http://www.w3.org/2001/XMLSchema”&gt;
<soap:Body>
<GetListResponse xmlns=”http://schemas.microsoft.com/sharepoint/soap/”&gt;
<GetListResult>
<List DocTemplateUrl=”/support/IT/AIX/Expenses2/Forms/template.xsn” DefaultViewUrl=”/support/IT/AIX/Expenses2/Forms/AllItems.aspx” MobileDefaultViewUrl=”” ID=”{1FD5DF1D-A70E-49B2-88FE-6C361E571692}” Title=”Expenses2″ Description=”” ImageUrl=”/_layouts/ima…….

So that means the output that you get when you call the web service has actually lesser nodes or the xml structure is no longer the same , which in turn means the XPath you have given may not work.

Current XPath in Query XML as you created – /soap:Envelope/soap:Body/defaultNS:GetListResponse/defaultNS:GetListResult/defaultNS:List/@ID

Replace it with – /defaultNS:List/@ID (with respect to the new node structure)

I hope it’s clear why we have changed the XPath, thats because our output begins with the node <List> and not <soap:Envelope> (Some basic XML stuff!!!)

Now we are done, just enable the actions that you disabled (Query XML & Log in History List – Id), republish and run your workflow. You’ll have the Id logged into your history list on completion of the workflow.

Happy Nintexing 🙂

Advertisements

4 thoughts on “XML parsing using Nintex

  1. Dear Manisha,
    I am having some problems with XPath. I want to retrieve A’s address from script below.

    A
    1

    B
    2

    I can do it perfectly without Nintex with //data[@name=’A’]/address but as Nintex has some namespaces it doesn’t work with Nintex. I have tried //defaultNS:[@name=’A’]/address or //defaultNS[@name=’A’]:address and anything but none of them works. Can you please help? Thanks!

  2. Hi Manisha, your post is really useful. Thanks for that.
    My question is , I can’t see XPathBuilder button/option using ‘QueryXML’ action. Do you have any idea why it’s hidden?

    • Hi Arsh,

      In the “Query XML” action, in the Output 1 section, there is a drop down to show “process using”. Please ensure that XPath is seected and not ‘none’, or ‘xslt’.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s