PDA

View Full Version : xpathQuery on Datapointer not working


innov8cs
07-16-2007, 12:46 PM
I can't seem to get an xpathQuery working inside of an ondata handler inside of a <datapointer>. I know it's most likely my syntax of the xpathQuery but any help would be appreciated.

I've got a dataset that successfully gets a full set of XML that looks as follows:

<Envelope>
<Body>
<loginResponse>
<outMsgtxt/>
<outSuccess>true</outSuccess>
<outCompanyNo>9</outCompanyNo>
<outCompanyName>ANGELA TEST COMPANY</outCompanyName>
</loginResponse>
</Body>
</Envelope>

I've then set up a datapointer so it has an ondata handler so I can perform some data specific functions on it. I'm using a datapointer because I've got two different scenarios of how the same dataset's data is supposed to work. But inside the ondata I can't seem to get the outSuccess, outCompanyNo, etc. values I want. Here's the specific code, simplified a bit:

<canvas>

<dataset name="loginDataset" type="http" src="http://www.mydomain.com" request="false" />

<datapointer name="loginSuccess" rerunxpath="true" datapath="loginDataset:/Envelope/Body/loginResponse">
<handler name="ondata">
<![CDATA[


if (this.xpathQuery('outSuccess/text()') == 'true')
{
One thing goes here
}
else
{
Anotherthing goes here
}
]]>
</handler>
</datapointer>

I've tried any number of things with the datapath like:

loginDataset:/Envelope/Body/loginResponse
loginDataset:/Envelope/Body/loginResponse/
loginDataset:/Envelope/Body/loginResponse/*
loginDataset:/Envelope/Body/*

Then combined it with:

this.xpathQuery('/outSuccess/text()')
this.xpathQuery('loginResponse/outSuccess/text()')
this.xpathQuery('/loginResponse/outSuccess/text()')
this.xpathQuery('outSuccess')

No matter what I seem to do, the value that this.xpathQuery() returns is always null.

Anyone see where I went wrong??


Thanks.

senshi
07-16-2007, 02:26 PM
Maybe your dataset isn't fully loaded at the time you perform the XPath-Query.
You can wait for the "ondata"-Event of the corresponding dataset and after this was fired, perform your queries:


<handler name="ondata" reference="loginDataset" >
/* your code */
</handler>

innov8cs
07-17-2007, 07:28 AM
I put some Debug.write messages in the firing of the ondata in the datapointer that shows the datapointer.data. The message is right before I do the xpathQuer() and it looks *exactly* as expected with the data filled in. Does that basically prove the dataset is fully loaded? I'm thinking it does.

But still, let me switch to a handler on the dataset and see if anything is different. I have to say if it is, I consider that a bug when an xpathQuery() works in one spot and not another.

innov8cs
07-17-2007, 10:27 AM
Just FYI, if I do loginDataset.getPointer().xpathQuery('/Envelope/Body/loginResponse/outSuccess/text()'); at the same point in my test of the datapointer's ondata event, it works fine. But any reference to an xpathQuery() on the datapointer fails. No matter what the query string is if I do it at the exact same time as the xpathQuery of the dataset that works, the datapointer always fails.

I suspect somehow the pointer is not being initialized correctly. I'm reporting this as a bug.

notzippy
07-17-2007, 12:09 PM
You shouldnt be using datapath inside a datapointer.
You should use xpath
The following willwork


<datapointer name="loginSuccess" xpath="loginDataset:/Envelope/Body/loginResponse">
<handler name="ondata">
<![CDATA[


if (this.xpathQuery('outSuccess/text()') == 'true')
{
One thing goes here
}
else
{
Anotherthing goes here
}
]]>
</handler>
</datapointer>

senshi
07-17-2007, 12:33 PM
You shouldnt be using datapath inside a datapointer.
You should use xpath
Good point, I didn't see that he used "datapath" instead of "xpath".

@innov8cs:
"datapath" as an attribute on a node is just a short-form for declaring a "datapath"-node.

So, this:

<node datapath="ds:/root/leaf[1]" />

is just a short-form for:

<node>
<datapath xpath="ds:/root/leaf[1]" />
</node>