View Full Version : using xpathQuery vs setXPath
scorpio
08-17-2004, 12:22 PM
Hi,
I have a dataset called testDataset which contains some nodes for example:
<xml>
<Lat>34.32343</lat>
<Long>49.32343</long>
</xml>
if I try to the following piece of code:
<code>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml/Lat");
var lat_position = dp.getTextNode();
dp.setXPath("testDataset:/xml/Long");
var long_position = dp.getTextNode();
debug.write( lat_position + ", " + long_position );
</code>
I get values for long_position and lat_position.
however when i try:
<code>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml");
var lat_position = dp.xpathQuery("Lat/text()");
var long_position = dp.xpathQuery("Long/text());
debug.write( lat_position + ", " + long_position );
</code>
i get nulls for both lat_position and long_position. why is that?
jakeh
08-25-2004, 03:39 PM
i am hung up on this as well...
perhaps use lower case characters throughout ?
you have used <Lat> .. </lat> and <Long> .. </long> in the dataset ..
try <lat> and <long>.
scorpio
08-26-2004, 07:25 AM
Hi,
I am sorry. It was a mistake on my part. The dataset actually looks like:
<xml>
<Lat>34.32343</Lat>
<Long>49.32343</Long>
</xml>
unmatched quot " .. " in this line ..
var long_position = dp.xpathQuery("Long/text());
should be ..
var long_position = dp.xpathQuery("Long/text()");
scorpio
08-27-2004, 05:06 AM
Sorry another typo: Even if I change it to the following code I still get the same result.
<code>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml");
var lat_position = dp.xpathQuery("Lat/text()");
var long_position = dp.xpathQuery("Long/text()");
debug.write( lat_position + ", " + long_position );
</code>
both examples work for me ..
<canvas width="500" height="200" debug="true">
<dataset name="testDataset" src="testDataset.xml" />
<script>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml/Lat");
var lat_position = dp.getNodeText();
dp.setXPath("testDataset:/xml/Long");
var long_position = dp.getNodeText();
debug.write( lat_position + ", " + long_position );
</script>
</canvas>
<canvas width="500" height="200" debug="true">
<dataset name="testDataset" src="testDataset.xml" />
<script>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml");
var lat_position = dp.xpathQuery("Lat/text()");
var long_position = dp.xpathQuery("Long/text()");
debug.write( lat_position + ", " + long_position );
</script>
</canvas>
__________________________________________
but note .. change your dp.getTextNode to dp.getNodeText (another typo perhaps ?) ..
If you run with debug enabled, you'll see better any typos like mistyped function names; the debugger will print a warning the first time it counters an attempt to call an undefined method or get an undefined variable. When you run without the debugger, errors like undefined vars and functions will be silently ignored.
scorpio
08-27-2004, 08:26 AM
I am really sorry for wasting ur time d~l. Yeah these were a bunch of typos in my post.
I tried these two examples on my dataset.
<canvas width="500" height="200" debug="true">
<dataset name="testDataset" src="testDataset.xml" />
<script>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml/Lat");
var lat_position = dp.getNodeText();
dp.setXPath("testDataset:/xml/Long");
var long_position = dp.getNodeText();
debug.write( lat_position + ", " + long_position );
</script>
</canvas>
<canvas width="500" height="200" debug="true">
<dataset name="testDataset" src="testDataset.xml" />
<script>
var dp = testDataset.getPointer();
dp.setXPath("testDataset:/xml");
var lat_position = dp.xpathQuery("Lat/text()");
var long_position = dp.xpathQuery("Long/text()");
debug.write( lat_position + ", " + long_position );
</script>
</canvas>
And yes I do have the debug enabled. It doesn't return any warnings either. Just nulls for the xpathQuery case and values for the setXPath case.
Is it possible that this is due to the fact that my dataset is dynamic and it is sometimes very big?
scorpio .. just to clarify .. I am no expert in this subject ..
as a relative newcomer to Laszlo, I try to troubleshoot some of these posted problems .. so that I can learn the ropes myself .. and I found this XPath example interesting .. since that is what I want to do ..
..
I would follow a systematic debugging approach to find exactly where the code breaks down ..
(a) do the apps work with the very basic testDataset.xml you posted (it works for me)?
(b) have you "XML validated" your very large dataset in an XML editor?
(c) try splitting the testDataset.xml until the apps work (cut it in half, then half again etc. .. until you find the point of failure/success).
(d) how dynamic is the dataset?
...
A few reference links I found ..
http://www.laszlosystems.com/~adam/blog/archives/000015.html
and from that blog ..
http://dev2dev.bea.com/products/wlworkshop/articles/JSchneider_XML.jsp
so it has been a useful exercise .. (typos apart).
Just a shot in the dark here, there is a bug in the current release of the LPS in which is dynamically loaded datasets that have nodes with attributes or text content strings longer than 64 KB may not work properly. This is fixed in the forthcoming LPS 2.2 release.
that is an interesting fresh clue ..
so I have just run a quick experiment ..
go to http://www.lipsum.com/ and generate 70 kbytes of random text in Latin to cut and paste into first <Lat></Lat> node .. in testDataset.xml
but this causes failure in debugger ..
then cut back the node text to that below ..
<xml>
<Lat>Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer faucibus nisl. Cras accumsan metus ut risus consectetuer tempus. Phasellus venenatis, tortor a porttitor ullamcorper, est arcu rhoncus nibh, quis ultricies purus nibh vel elit. Proin ornare molestie dui. Vestibulum vel purus porttitor felis gravida adipiscing. Duis quis felis sed leo blandit sollicitudin. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos hymenaeos. Mauris lorem ante, sollicitudin eu, ornare sit amet, facilisis non, tellus. Phasellus nulla mi, rutrum auctor, tincidunt ut, porttitor in, enim. In sed elit. Fusce mattis. Lorem ipsum dolor sit amet, consectetuer adipiscing elit.
</Lat>
<Long>69.32343</Long>
</xml>
The debugger only prints out up to this point .. "Cras accumsan metus ut" .. i.e. truncated at 100 + characters. and does not print out <Long></Long>
significant?
Well, the debugger has a string-length parameter at which it truncates strings and puts "...", so that is behaving ok. What was the failure mode with the larger example? Can you post the code or email it to me at hqm@ai.mit.edu ?
I'll send separately the full test Latin text (70K) although you can generate it at the link given .. http://www.lipsum.com/
here is the error message seen in debugger
______________________________________________
test01.lzx:6: reference to undefined variable 'testDataset'
test01.lzx:6: undefined object does not have a property 'getPointer'
test01.lzx:7: undefined object does not have a property 'setXPath'
test01.lzx:8: undefined object does not have a property 'getNodeText'
______________________________________________
when I reduced the string length below the truncation point the app worked .. and showed the expected output ..
this is the dataset that works ..
<xml>
<Lat>
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer faucibus nisl.
</Lat>
<Long>69.32343</Long>
</xml>
with output thus ..
Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Integer faucibus nisl., 69.32343
definitely string length sensitive ..
It sounds like the 64K string length bug. This is fixed in the 2.2 release, it will be available quite soon for download. The workaround is to break strings into less than 64k pieces...
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.