PDA

View Full Version : Problem with newline


intellagent
04-20-2009, 05:28 AM
Hi,

Generating an lzx file instead of a normal newline character I get 
 characters. The command is: de.appendChild(new lz.DataText('\n ')) where de is an lz.DataElement. It was correct under lps3.4.x

Who can help?

Thanks

mjessup
04-20-2009, 10:38 AM
That doesn't seem wrong. 
 is the proper escape for a new line (ascii hex code 'A'). I have used newlines in my data and it serializes/ deserializes properly. Are you serializing or accessing the raw text via the 'data' attribute of DataText? (I am using LPS 4.1.1). Do you have a longer example that displays the 
 where you want to see the newline instead of the escape sequence?

intellagent
04-20-2009, 10:53 AM
I generate an lzx file, which is now syntactically not correct
Here is the first few lines from the earlier generated lzx file:

<library>
<myAblak elsoMezo="TMsznev" id="TA001" name="TA001" x="${adatok.width/10 + 10}" y="${nevsorKeretKulso.y}" width="${9*adatok.width/10 -20}" height="${nevsorKeretKulso.height - saveCancelBtns.height}" bgcolor="0xA0B2B1" visible="false" focustrap="true" elsoAblak="true">
<myVonal id="V001" width="${parent.width}" y="${0.07 * parent.height}" align="center"/>
<text id="FC001" name="FC001" x="${V001.x}" y="${V001.y - 25}" fontsize="18" text="SzemĂİlyi adatok"/>
---------------------------------------------------------
...and here is a few lines from the bad lzx file:

<library>&#xa; <myAblak elsoMezo="TMsznev" id="TA001" name="TA001" x="${adatok.width/10 + 10}" y="${nevsorKeretKulso.y}" width="${9*adatok.width/10 -20}" height="${nevsorKeretKulso.height - saveCancelBtns.height}" bgcolor="0xA0B2B1" visible="false" focustrap="true" elsoAblak="true">&#xa; <myVonal id="V001" width="${parent.width}" y="${0.07 * parent.height}" align="center"/>&#xa; <text id="FC001"

---------------------------------------------------------

You can see the difference after the <library> element.

The code which generates these lines are identical:
......
ablakSzoveg = new LzDataElement('library');
ablakSzoveg.appendChild(new LzDataText('\n '));
ablakSzoveg.appendChild(ablakForTorzs);
ablakSzoveg.appendChild(new lz.DataText('\n'));
............

I really don't understand.

mjessup
04-20-2009, 11:45 AM
I actually meant how you are getting the text in your example from the laszlo data elements in memory. I am guessing you are using the serialize method as from the docs on LzDataNodeMixin. If this is the case I would think the simplest solution would be to create a subclass of LzDataText and overrride the serialize method:


<class name="MyDataText" extends="DataText">
<method name="serialize" args="len">
return this.data;
</method>
</class>
...
ablakSzoveg = new LzDataElement('library');
ablakSzoveg.appendChild(new lz.MyDataText('\n '));
ablakSzoveg.appendChild(ablakForTorzs);
ablakSzoveg.appendChild(new lz.MyDataText('\n'));
...

Then you can return something which is syntactically correct for laszlo, stopping the escape of the newline (or anything else that laszlo may not like), instead of the general XML syntactically correct output as in your example above. And of course you could do the same if necessary for LzDataElement. (Disclaimer: I'm not at my development machine so please excuse any typos that might be in the example code).

intellagent
04-20-2009, 12:03 PM
Now this is the errormessage I have got:
undefined superclass DataText for class MyDataText

:mad:

I feel myself a little bit stupid...

senshi
04-20-2009, 12:51 PM
You can't extend lz.DataText or lz.DataElement as lzx-classes, I'd propose to roll out your own xml-formatter if you need special handling for the output:



<canvas debug="true">
<dataset name="ds" src="http://www.laszlosystems.com/cgi-pub/weather.cgi?zip=11001" request="true" />
<handler name="ondata" reference="ds" >
output.setAttribute("text", output.escapeText(prettyPrint(ds)));
</handler>
<method name="prettyPrint" args="xmlnode" ><![CDATA[
var escapeXml = function (s) {
var r = "";
var escChars = {'&': '&amp;', '<': '&lt;', '>': '&gt;', '"': '&quot;'};
for (var i = 0, len = s.length; i < len; ++i) {
var c = s.charAt( i );
r += (escChars[c] || c);
}
return r;
}
var txt = "";
var indent = "";
var next, node = xmlnode;
while (1) {
var type = node.nodeType;
if (type == 3) {
txt += indent + escapeXml(node.data) + "\n";
} else if (type == 1 || type == 9) {
var attr = "";
var attrs = node.attributes;
for (var k in attrs) {
attr += " " + k + "=\"" + escapeXml(attrs[k]) + "\"";
}
if ((next = node.childNodes[0])) {
txt += indent + "<" + node.nodeName + attr + ">\n";
node = next;
indent += "\t";
continue;
} else {
txt += indent + "<" + node.nodeName + attr + "/>\n";
}
}
while (! (next = node.getNextSibling())) {
node = node.parentNode;
indent = indent.substr(1);
txt += indent + "</" + node.nodeName + ">\n";
if (node === xmlnode) {
return txt;
}
}
node = next;
}
return null;
]]></method>
<text name="output" multiline="true" width="90%" />
</canvas>