PDA

View Full Version : converting datapointer to a dataset


stevie
09-01-2005, 02:05 AM
I am trying to take some text from a node which happens to an string of xml and convert this to its own dataset that can then be used elsewhere.
I have tried the LzDataNode method stringToLzData but cannot seem to get this working.

If anyone has got an example of this please let me know.

To help here's the code I am trying:

var dsp = canvas.datasets.Dset.getPointer(); dsp.setXpath('item/getContactListResponse/getContactListReturn');

// the text at the above node is a string of xml text that is required as a dataset

Many thanks

Stevie

mmenti
09-01-2005, 03:46 AM
Something like this may do what you want (assumes newDset is empty to start with):

var dsp = canvas.datasets.Dset.getPointer();
var de = dsp.xpathQuery('item/getContactListResponse/getContactListReturn');

var newdsp = canvas.datasets.newDset.getPointer();
newdsp.p.appendChild(de);

stevie
09-01-2005, 04:33 AM
Thanks for that,

Unfortunatley the new dataset gets populated as

<getContactListReturn>
.
.
string
.
.
</getContactListReturn>

so the data is still the text associated with the node <getContactListReturn> and not xml in its own right.

That's where I thought the LzToString mehod might work in this case.

Any more thoughts?

Stevie

mmenti
09-01-2005, 04:53 AM
In that case your xpath query should be changed to match the text() rather than then node itself, and then convert the returned string to a node when adding it to the new dataset - something along the lines of this:

var de = dsp.xpathQuery('item/getContactListResponse/getContactListReturn/text()');

var newdsp = canvas.datasets.newDset.getPointer();
newdsp.p.appendChild(LzDataNode.stringToLzData(de) );

stevie
09-01-2005, 05:02 AM
Thanks for your quick response!

I seem to get the error 'call to undefined method 'stringToLzData'' - which what I was getting before.

Has anyone else tried this method and got it working or is this a bug?

Stevie

mmenti
09-01-2005, 05:06 AM
I've used stringToLzData many times without problems ... does the below give you the same error?

var element = LzDataNode.stringToLzData(de);
newdsp.p.appendChild(element);

Also, you obviously have to make sure the string you're trying to convert is valid XML.

stevie
09-01-2005, 05:40 AM
This gives the same error. I have tried using a simple xml string too with the same results.

The error though seems to say the method is not recognised in the libraries.

I'm running 3.0b1 and a colleague has got the same error on 3.0b2.

Do you have an example of this working?

Stevie

mmenti
09-01-2005, 05:47 AM
I've never had problems with this, either under 3.0.2 (which I am running now), or previousy under 3.0. Below is some simple example code from my app that definitely works for me (the app is using stringToLzData in many different places). You may want to upgrade to the latest released version (3.0.2)?

rdPtr = dsResponse.getPointer();
rdPtr.setXPath('Page');
var navStr = '<Navigation Type="Next" IsSelected="true"/>';
var navElm = LzDataNode.stringToLzData(navStr);
rdPtr.p.appendChild(navElm);
var retStr = rdPtr.serialize();
return(retStr);

stevie
09-02-2005, 04:09 AM
I've been doing some more tests with the LzDataNode.stringToLzData() method in various contexts but I'm still getting the same error.

What could cause this error I wonder?

Stevie