AnsweredAssumed Answered

Using XPath to set variables

Question asked by Mike.M on Jan 9, 2012
Latest reply on Jan 18, 2012 by Mike.M
Hi all,
I'm having trouble using XPath to pull data from a soap response I'm getting when I XOG out a cost plan. I've been able to use the <gel:log> tag to debug however I'm stymied at this point. Here's what I have done:

1) Login
2) Parse the SessionID out using <gel:set asString="true" select="$auth/SOAP-ENV:Envelope/SOAP-ENV:Body/xog:SessionID/text()" var="sessionID" />
3) XOG out a cost plan using
<soap:invoke endpoint="${XOGURL}/niku/xog" var="cstPlanQryResult">
     <soap:message>...SOAP Envelope Here...</soap:message>
4) Set a variable 'costNode' to contain the entire SOAP response using <gel:set var="costNode" select="$cstPlanQryResult" asString="true"></gel:set>
5) Show the response in the Clarity logs using <gel:log level="warn" category="SOAPResponse" message="${costNode}" />

So that's all good if I want to just return the entire response, except I want to use XPath to select a Detail node in the response (eventually, I want to select a Detail node for a specific line item but I haven't gotten that far yet). Based on what is logged, I see that the response is as follows:
<?xml version="1.0" encoding="UTF-8"?> <soapenv:Envelope xmlns:soapenv=""> 
          <ReadCostPlanResponse xmlns=""> 
               <NikuDataBus xmlns:xsi="" xsi:noNamespaceSchemaLocation="../xsd/nikuxog_costPlan.xsd"> 
                    <Header externalSource="NIKU" version=""/> 
                         <CostPlan code="00000046" finishPeriod="Feb 2012" investmentCode="P201103311" investmentType="PROJECT" isPlanOfRecord="1" name="Forecast" periodType="MONTHLY" primaryPlanBy="CHARGECODE" secondaryPlanBy="TRANSCLASS" startPeriod="Jan 2011" status="SUBMITTED"> 
                                   <Detail detail2Name="Software" detailName="capital">
...More detail lines, then closing the call...
Here's where I'm getting stuck. I can use XPath to select either the Envelope or Body:
Envelope <gel:set var="costNode" select="$cstPlanQryResult/soapenv:Envelope" asString="true"></gel:set>
Body <gel:set var="costNode" select="$cstPlanQryResult/soapenv:Envelope/soapenv:Body" asString="true"></gel:set>

But when I try to go one node deeper (<gel:set var="costNode" select="$cstPlanQryResult/soapenv:Envelope/soapenv:Body/ReadCostPlanResponse" asString="true"></gel:set>), the XPath isn't giving me anything.

So now I'm turning to you - please help! Eventually, I want to set the costNode variable to a specific Detail node using the detail2Name attribute.