Unable to parse XML

  • 5 September 2016
  • 16 replies
  • 26 views

Badge +7

Hi,

I query a custom Web Service in Nintex Workflow 2013 and get the following XML.

Somehow, I can't parse it using the Query XML Action. As a result, I get the orignal XML data back.

Can anybody help me out?

<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
 <s:Body>
  <GetPersonIdListResponse xmlns="http://tempuri.org/">
   <GetPersonIdListResult xmlns:a="http://schemas.datacontract.org/2004/07/xyz" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
    <a:Error>_NoError</a:Error>
    <a:ErrorMessage/>
    <a:Result>true</a:Result>
    <a:Count>4</a:Count>
    <a:Ids xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays">
     <b:int>100108</b:int>
     <b:int>100123</b:int>
     <b:int>100375</b:int>
     <b:int>103741</b:int>
    </a:Ids>
    <a:Objekt>Person</a:Objekt>
    <a:SqlCommand>SELECT DISTINCT P.PERSONID FROM PERSON P INNER JOIN PERSONORG PO ON PO.PERSONID=P.PERSONID INNER JOIN ORGEINHEIT O ON O.ORGEINHEITID=PO.ORGEINHEITID INNER JOIN KOSTENSTELLE K ON K.KOSTENSTELLE_PKEY=O.KOSTENSTELLE_FKEY  WHERE K.KREIS LIKE '501' AND P.MODIFYDATE&gt;=TO_DATE('2015.08.12 00:00:00', 'yyyy/mm/dd hh24:mi:ss') AND P.MODIFYDATE&lt;TO_DATE('2016.08.10 00:00:00', 'yyyy/mm/dd hh24:mi:ss') ORDER BY 1</a:SqlCommand>
    <a:StrIds xmlns:b="http://schemas.microsoft.com/2003/10/Serialization/Arrays"/>
   </GetPersonIdListResult>
  </GetPersonIdListResponse>
 </s:Body>
</s:Envelope>


16 replies

Badge +11

Hi Raphael,

can you maybe explain/show us how you configured your XML query action so we can try to find the source of the error?

Thanks

Philipp

Badge +7

Hi

This is how my configuration looks like...

... and here is the result

Badge +11

Hi Raphael,

first of all I have to say that the "Run Now" doesn't always work as expected. Especially if your XPath isn't valid, the result will often show useless stuff (just my experience) e. g. the whole XML.

It seems like you have used the XPath builder for your XPath query. I tested this myself and could reproduce your problem. I also used another XPath generator with no success.

Additionally I created a little (dirty) XPath that should do the trick:

//*[local-name()="int"][1]

This works fine if you test it on this site: Free Online XPath Tester / Evaluator

but it doesn't work on the XML Query action in Nintex and I have no idea why. The XML Query action DOES work in general, I have used it many times. But it seems like some of the XML returned by the web services is just too messy even for the .NET framework itself.

I would really love to hear some Nintex dev or maybe a user who had some time to deep dive into this topic to tell us about the magic that is happening there.

Sorry I can't help you at the moment.

Cheers

Philipp

Userlevel 5
Badge +14

folowing XPath expression should work

/s:Envelope/s:Body/defaultNS:GetPersonIdListResponse/defaultNS:GetPersonIdListResult/a:Ids/b:int[1]

you have had doubled namespace specifications for Ids and int

Badge +7

HI

Thanks for your help.

Just to make sure I correctly understand you: To achieve the same result like you, I have to modify the XML as well, right?

The combination of my original XML and your XPath expression does not seem to work.

Userlevel 5
Badge +14

no, just use xpath I posted.

I copy-pasted your source XML as you posted it in original question with no change.

I've meant following namespace specification doubled in your xpath:

/s:Envelope/s:Body/defaultNS:GetPersonIdListResponse/defaultNS:GetPersonIdListResult/
defaultNS:a:Ids/defaultNS:b:int[1]

do you test in run now or do you run whole workflow?

do you get any error?

Badge +7

And I copy-pasted your XPath Expression.

This is very odd. I get the same result if I run the whole workflow or test it in "run now" but not the single ID like in your screenshot.

Userlevel 5
Badge +14

how did you get the XML you posted in the question?

is it really the input of query XML action? I mean if you got it from run now in call webservice action or from some 3rd party tools it need not exactly be what inputs into query XML

I guess you supply a variable to the query XML action that holds the XML to be parsed.

try to send it to yourself by mail action (as plain text!) and compare it to before posted XML.

you may want as well to attach that output to this thread as text file to avoid some HTML formatting issues

Badge +7

Ok, will try that next. Thanks for your support so far. 

Badge +11

Thanks a lot ‌, your XPath is working for me as well!

However, the XPath builder returns the wrong XPath-expression and is not to be relied upon.

Cheers

Philipp

Userlevel 5
Badge +14

I as well do not have very good experiences with query builder and have compiled above xpath by hand.

but I've tested builder for this specific case and it seems it works correctly for me

Badge +7

‌ & ‌ you guys are awesome! Had to run the workflow. "Run now" didn't show the correct result. Now it's working. Thanks for your support, appreciate it!

Badge +1

Hello All,

I'm trying to accomplish the same thing and having trouble parsing the XML to get the Employee ID.  The value of the Employee ID is in the 90th 'PropertyData' node and my xpath is not working.  Here is my xpath:

/soap:Envelope/soap:Body/defaultNS:GetUserProfileByNameResponse/defaultNS:GetUserProfileByNameResult/defaultNS:PropertyData[4]/defaultNS:Values/defaultNS:ValueData/defaultNS:Value/@xsi:type

This is the XML from the Call Web Service:

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<soap:Body>
<GetUserProfileByNameResponse xmlns="http://microsoft.com/webservices/SharePointPortalServer/UserProfileService">
<GetUserProfileByNameResult>
<PropertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<IsValueChanged>false</IsValueChanged>
<Name></Name>
<Privacy></Privacy>
<Values>
<ValueData>
<Value xmlns:q1="http://microsoft.com/wsdl/types/" xsi:type="q1:guid"></Value>
</ValueData>
</Values>
</PropertyData>
<PropertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<IsValueChanged>false</IsValueChanged>
<Name>State</Name>
<Privacy>Public</Privacy>
<Values>
<ValueData>
<Value xsi:type="xsd:string"></Value>
</ValueData>
</Values>
</PropertyData>
<PropertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<IsValueChanged>false</IsValueChanged>
<Name>ZipCode</Name>
<Privacy>Public</Privacy>
<Values>
<ValueData>
<Value xsi:type="xsd:string"></Value>
</ValueData>
</Values>
</PropertyData>
<PropertyData>
<IsPrivacyChanged>false</IsPrivacyChanged>
<IsValueChanged>false</IsValueChanged>
<Name>employeeID</Name>
<Privacy>Private</Privacy>
<Values>
<ValueData>
<Value xsi:type="xsd:string">0987654</Value>
</ValueData>
</Values>
</PropertyData>
</GetUserProfileByNameResult>
</GetUserProfileByNameResponse>
</soap:Body>
</soap:Envelope>

Its the last PropertyData node and the value I'm trying to get is 0987654 from the employeeID node.  The value I am getting with the XPath is 'xsd:sring'

Userlevel 5
Badge +14

with @xsi:type at the very end you asked for that attribute value, so you got it.

just remove it from your xpath, make sure 'Return result' is set to text and you should get what you need

Badge +1

Thanks for your quick response Marian,

I removed @xsi:type but got an error.  However, I was able to get the value I need by modifying the xPath to the following:

/soap:Envelope/soap:Body/defaultNS:GetUserProfileByNameResponse/defaultNS:GetUserProfileByNameResult/defaultNS:PropertyData[4]/defaultNS:Values/defaultNS:ValueData/defaultNS:*[local-name()='Value']

Thanks for your help

Userlevel 5
Badge +14

it should work.

this is tested on your data

..../defaultNS:*[local-name()='Value'] and ..../defaultNS:Value selectors do the same

Reply