By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,836 Members | 2,181 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,836 IT Pros & Developers. It's quick & easy.

specify html target value based on xml element

P: n/a
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
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Richard G. wrote:
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").it em(i).text+'">')
document.write(xmlDoc.getElementsByTagName("ARTIST ").item(i).text)
document.write('</a></td></tr>')
}
</script>
</table>
</body>
</html>

-------
regards
Bart
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.