PDA

View Full Version : accessing xpath elements in a tag attribute


tangollama
03-04-2003, 01:03 PM
I have the following code

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


<canvas width="100" height="800" title="CommNav Menubar">
<script>
if (bgColor == null) {
this.setBGColor(0xffffff);
} else {
Debug.Write('0x' + bgColor);
this.setBGColor('0x' + bgColor);
}
</script>
<splash/>

<!-- IMAGE RESOURCES -->
<resource src="logo.jpg" name="bg_img" />
<resource src="splash_logo.jpg" name="splash_img" />

<!-- FONT RESOURCES -->
<font src="helmetr.ttf" name="Helvetica"/>
<font src="helmetb.ttf" name="Helvetica" style="bold" />
<font src="lztahoe8b.ttf" name="Bold"/>

<!-- DATA SOURCE -->
<dataset name="portalData" autorequest="true"
src="http://jworrall.mars.dev.commnav.com:8014/mars/templates/jworrall/portalData.jsp"/>

<view id="datarows" width="immediateParent.width" resource="splash_img">
<!-- VIEWS of datarows -->
<simplelayout axis="y" />
<view width="immediateParent.width" height="20"
clickable="true" name="result" onclick="callDesktop(nameid/text())"
datapath="portalData:/sbh[1]/desktopList[1]/desktop">
<!--VIEWS-->
<simplelayout axis="x" />
<view id="icon" name="icon" resource="" />
<text datapath="name/text()"/>
<method name="callDesktop" args="nameid">
var nameId = nameid;
Debug.Write(nameId);
LzBrowser.loadURL("javascript:window.setDesktop(document.changeDeskto pFrm,null,'"+nameId+"')");
</method>
</view>
</view>
</canvas>


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


the xml document I'm passing is the following:


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


<sbh>
<desktopList>
<desktop>
<desktopid>2138</desktopid>
<nameid>home</nameid>
<name>Home</name>
<icon>/images/icons/home.gif</icon>
<currentFlag>true</currentFlag>
</desktop>
<desktop>
<desktopid>2741</desktopid>
<nameid>home2</nameid>
<name>home2</name>
<icon>/images/icons/file_document.gif</icon>
</desktop>
</desktopList>
</sbh>


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


how can I access the nameid element to call the given method which calls a javascript function in the surrounding page? I have tried several other methods with little success. Probably a very simple question but I'm a little lost of the documentation.

On another note, documenting that the autorequest attribute on the dataset must be set to true to get the request to execute (or even what the attribute actually is) might be helpful. thanks.

antun
03-04-2003, 02:11 PM
Hey tangollama

You would use the getXPath() method on the datapath. See my rendition of your code:-


<canvas width="800" height="800" title="CommNav Menubar" debug="true">
<script>
if (bgColor == null) {
this.setBGColor(0xffffff);
} else {
Debug.Write('0x' + bgColor);
this.setBGColor('0x' + bgColor);
}
</script>
<splash/>

<!-- FONT RESOURCES -->
<font src="helmetr.ttf" name="Helvetica"/>
<font src="helmetb.ttf" name="Helvetica" style="bold" />
<font src="lztahoe8b.ttf" name="Bold"/>

<!-- DATA SOURCE -->
<dataset name="portalData">
<sbh>
<desktopList>
<desktop>
<desktopid>2138</desktopid>
<nameid>home</nameid>
<name>Home</name>
<icon>/images/icons/home.gif</icon>
<currentFlag>true</currentFlag>
</desktop>
<desktop>
<desktopid>2741</desktopid>
<nameid>home2</nameid>
<name>home2</name>
<icon>/images/icons/file_document.gif</icon>
</desktop>
</desktopList>
</sbh>
</dataset>

<view id="datarows" width="immediateParent.width" >
<!-- VIEWS of datarows -->
<simplelayout axis="y" />
<view width="immediateParent.width" height="20"
clickable="true"
name="result"
onclick="callDesktop()"
datapath="portalData:/sbh[1]/desktopList[1]/desktop">
<!--VIEWS-->
<simplelayout axis="x" />
<view id="icon" name="icon" />
<text datapath="name/text()"/>
<method name="callDesktop">
var nameId = this.datapath.getXPath('nameid/text()');
debug.write( nameId );
LzBrowser.loadURL("javascript:window.setDesktop(document.changeDeskto pFrm,null,'"+nameId+"')");
</method>
</view>
</view>
</canvas>


We know about the lack of good reference material, and I can assure you we are working really hard on this right now.

For debug purposes, you can include the XML document inline (like I did) while you build your app, then move to a http request later.

-Antun