specify html target value based on xml element

Discussion in 'XML' started by Richard G., Jun 24, 2004.

  1. Richard G.

    Richard G. Guest

    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
     
    Richard G., Jun 24, 2004
    #1
    1. Advertising

  2. 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").item(i).text+'">')
    document.write(xmlDoc.getElementsByTagName("ARTIST").item(i).text)
    document.write('</a></td></tr>')
    }
    </script>
    </table>
    </body>
    </html>

    -------
    regards
    Bart
     
    Bart Van der Donck, Jun 27, 2004
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mike
    Replies:
    5
    Views:
    9,858
    Juan T. Llibre
    Mar 12, 2005
  2. Thomas Stien
    Replies:
    0
    Views:
    494
    Thomas Stien
    Oct 18, 2004
  3. helene.bh
    Replies:
    7
    Views:
    837
  4. James
    Replies:
    2
    Views:
    1,015
    Joe Kesselman
    Jul 28, 2007
  5. HANM
    Replies:
    2
    Views:
    769
    Joseph Kesselman
    Jan 29, 2008
Loading...

Share This Page