PDA

View Full Version : tag attributes as parameters read from an external data file


lyndonwong
09-17-2003, 08:34 PM
Hi Laszlo, I'm trying to set parameters of an .lzx app using an external XML datasource.

Let's say I want to determine the color of some text by reading an XML parameter list such as:

pWeather_parameters.xml -----------------------------

<parameters>
<titleColor>#CCCCFF</titleColor>
</parameters>

To use that in an .lzx app, I declare a dataset:

<!-- App parameter values in an external XML file -->
<dataset name="pWeather_parameters" src="pWeather_parameters.xml" />


I can read the above titleColor parameter successfully with the following code, which displays the string "#CCCCFF":

<view name="externalText" datapath="pWeather_parameters:/parameters/">

<text fontsize="12" width="170" datapath="titleColor/text()" />


But how would I access the same above titleColor parameter and assign it to the fgcolor attribute of another text string?

<text fontsize="12" width="170" fgcolor="${parent.externalText.titleColor/text()}">This should be the fgcolor!</text>

I bumbled with a few attempts but failed. Can you steer me toward the right approach? -- thanks.

antun
09-17-2003, 09:54 PM
First you don't really need to set it to a text field first, like you're doing, though I can see how you arrived at that. Instead set up a datapointer to retrieve the color:


<datapointer xpath="pWeather_parameters:/parameters/titleColor/text()">
<method event="ondata" args="d">
mytextfield.setAttribute('fgcolor', d);
</method>
</datapointer>


Something like the above should work. You can always debug.write() the value of d in the method to check what's being passed back.

See this post on the color:

http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=243&highlight=bgcolor

Bear in mind even if you do change it to 0x... format, it'll still be a string. You might have to parseInt() it to convert it into a number.

-Antun