PDA

View Full Version : Why "text not allowed here"?


laszfellow
10-09-2006, 10:44 AM
I wish to create a non-visual text node tag.
I would use it to store sql statements or not immediately executed scripts.
e.g.


<textNode name='setCookie'>
document.cookie = 'ID=1234';
alert(document.cookie);
</textNode>

<textNode name='getAddr'>
select *
from emp
where empid = '1234'
</textNode>


To achieve that, I extended node class, simplistically shown below.


<library>
<class name='textNode' extends='node'>
<method name='getText'>
<![CDATA[
tx = text.split("&amp;apos;").join("'");
return tx;
]]>
</method>
</class>
</library>


When run on browser, I am able to withdraw tag body by setCookie.text and getAddr.text, respectively. However, compilation shows me the message "text not allowed here". Which means Laszlo seeks to control whether I could put text between tags (why?).

Is there a class tag which I could extend and which would allow me to put text in the tag body without and compilation warnings.

Alternatively, what should I do to inform Laszlo compiler that I have a benign need to include text into the tag body? Thereby achieving my desired tag class without unnerving the Laszlo compiler's need to control whether I embed text between a pair of tags.

=============== thefreedictionary.com ================
un·nerve (n-nûrv)
tr.v. un·nerved, un·nerv·ing, un·nerves
1. To deprive of fortitude, strength, or firmness of purpose.
2. To make nervous or upset.
==================================================

senshi
10-09-2006, 01:38 PM
Just look at: http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=378

or:


<canvas debug="true" >

<class name="textNode" extends="node" >
<attribute name="text" type="text" />
</class>

<textNode>
Hello from the textNode!
</textNode>

</canvas>

jcmaxx
10-09-2006, 01:41 PM
I think you just need to include a text attribute in you class declaration. From Chapter 30. Extending Classes (http://www.laszlosystems.com/lps-3.2/docs/guide/class-inheritance.html) of the Developer's Guide:A user-defined class can also handle text content by defining an attribute named text with a value of text (for plain text) or html (for XHTML text), like <attribute name="text" type="text">. There is another text type available called string which allows you set a text string as an attribute, but does not allow text content.

laszfellow
10-09-2006, 03:19 PM
Thanks guys.

As y'all could see, the text is url-encoded when referenced, so that,

a = 'id=1234';

becomes

a = &apos;id=1234&apos;

In order to submit the text to LzBrowser.loadJS, I had to unencode it by


tx = text.split("&apos;").join("'");
return tx;


Due to lack of regex substitution in action script (as opposed to browser javascript) there is a lot of unencoding to do for each encoded element.

Is there a way to allow the text to be referenced unencoded? Perhaps an attribute setting?

laszfellow
10-10-2006, 12:33 PM
I decided to do this ...
Any further suggestions?


<library>
<script>
<![CDATA[
function unencode(tx)
{
return tx
.split("&amp;amp;").join("&")
.split("&apos;").join("'")
.split("&amp;quot;").join('"')
.split("&lt;").join("<")
.split("&gt;").join(">")
;
}
]]>
</script>

<class name='textNode' extends='node'>
<attribute name="text" type="text" />
<method name='getText'>
return unencode(text);
</method>
</class>

<class name='htmlNode' extends='node'>
<attribute name="text" type="html" />
<method name='getText'>
return unencode(text);
</method>
</class>

</library>

ptw
10-11-2006, 05:07 AM
Sounds like you should file an enhancement request for LzBrowser. It has xmlEscape, you want xmlUnescape.