specify html target value based on xml element

R

Richard G.

Hi All,

I am newbie in XML.

I am designing a dynamic menu and retrieving data from xml.
I have the xml file something like this:

<?xml version="1.0" ?>
<ROOT>

<node value="1.0" image="folder.gif" url_value="my_home.html"
target="main_win">
</node>
<ROOT>

I have no problem retriving the element to the html table menu.
However I can't find a way to set the target value based on the xml
data. for example

<TABLE id=PrimaryTable dataSrc=#TheData cellSpacing=0 cellPadding=0
border=0>
<TBODY>
<TR>
<TD><IMG dataFld=image id=Icon>
<a datafld="menu_url"><SPAN dataFld=value></SPAN></a>
</TD>
</TR>

Based on the sample above i can retrive data from the xml data file
and created the hyperlink point to "menu_url" attribute of the
element. But I need to set the target where we can decide where to
open this url. something like <a href='abc.htm' target="new_win">

Does anyone know how to do that?

Any help is greatly appreciated.

Best Regards,

Richard
 
B

Bart Van der Donck

Richard said:
I have no problem retriving the element to the html table menu.
However I can't find a way to set the target value based on the xml
data.
i can retrive data from the xml data file
and created the hyperlink point to "menu_url" attribute of the
element. But I need to set the target where we can decide where to
open this url. something like <a href='abc.htm' target="new_win">

You can use client script to read out a "TARGET" value. I made an
example that should help you further:

--------------------------------------
This would be your xml file:
--------------------------------------

<?xml version="1.0" encoding="ISO-8859-1"?>
<CATALOG>
<CD>
<TITLE>Empire i Burlesque</TITLE>
<ARTIST>Bob Dylan</ARTIST>
<URL>http://www.bob-dylan.com</URL>
<TARGET>_self</TARGET>
</CD>
<CD>
<TITLE>Hide your heart</TITLE>
<ARTIST>Bonnie Tyler</ARTIST>
<URL>http://www.bonnie-tyler.com</URL>
<TARGET>_top</TARGET>
</CD>
<CD>
<TITLE>Greatest Hits</TITLE>
<ARTIST>Dolly Parton</ARTIST>
<URL>http://www.dolly-parton.com</URL>
<TARGET>_blank</TARGET>
</CD>
</CATALOG>

--------------------------------------
This would be your script file:
--------------------------------------

<html>
<body>
<table border="1">
<tr>
<th>Title</th>
<th>Artist</th>
</tr>
<xml src="cds.xml" id="xmlDoc" async="false"></xml>
<script language="javascript">
for (var i=0;i<(xmlDoc.documentElement.childNodes.length);i++)
{
document.write('<tr><td>')
document.write(xmlDoc.getElementsByTagName("TITLE").item(i).text)
document.write('</td><td>')
document.write('<a href='+xmlDoc.getElementsByTagName("URL").item(i).text)
document.write(' target="'+xmlDoc.getElementsByTagName("TARGET").item(i).text+'">')
document.write(xmlDoc.getElementsByTagName("ARTIST").item(i).text)
document.write('</a></td></tr>')
}
</script>
</table>
</body>
</html>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,042
Latest member
icassiem

Latest Threads

Top