DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 3 of 3

Thread: *HELP* trying to form hyperlinks from XML data

  1. #1
    S. Brower Guest

    *HELP* trying to form hyperlinks from XML data


    Please help!
    I would expect the following sample to result in a column titled Email where
    each entry from the XML file displays as clickable item to send an email.
    Instead what I get is the stuff in the CDATA tag - verbatim.

    How do I create the email addresses dynamically?

    Thanks in advance,
    SB

    =============XML FILE======================
    <?xml version="1.0"?>
    <employees>
    <employee EID="1">
    <Last>Doe</Last>
    <First>John</First>
    <Title>Field Representative</Title>
    <Email><![CDATA["John Doe" <jdoe@nowhere.com>]]></Email>
    </employee>
    </employees>


    ===========HTML FILE=================
    <HTML>
    <BODY topmargin="1" leftmargin="1" onmousedown="push_me()" onmousemove="window.status
    = 'Employee Directory'">
    <XML id=xmldso></XML>
    <SCRIPT>
    xmldso.async = false;
    xmldso.load("eedir.xml");
    var xmldoc = xmldso.cloneNode(true);

    function sort(xsldoc){
    syncChanges();
    xmldoc.documentElement.transformNodeToObject(xsldoc.documentElement,xmldso.XMLDocument);
    }

    function syncChanges(){
    for (var i=0;i<xmldso.documentElement.childNodes.length;i++)
    {
    var currentNode = xmldso.documentElement.childNodes(i).cloneNode(true);
    var query = "employee[EID = '" + currentNode.childNodes.item(0).text
    + "']";
    var origNode = xmldoc.documentElement.selectSingleNode(query);
    }
    }
    </SCRIPT>
    <TABLE DATASRC='#xmldso' BORDER CELLPADDING=3>
    <THEAD>
    <TH style="font-family: ARIAL; font-size: 8pt">Last</TH>
    <TH style="font-family: ARIAL; font-size: 8pt">First</TH>
    <TH style="font-family: ARIAL; font-size: 8pt">Title</TH>
    <TH style="font-family: ARIAL; font-size: 8pt">Email</TH>
    </THEAD>
    <TR>
    <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="Last"></SPAN></TD>
    <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="First"></SPAN></TD>
    <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="Title"></SPAN></TD>
    <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="Email"></SPAN></TD>
    </TR>
    </TABLE>
    </BODY>
    </HTML>

  2. #2
    S. Brower Guest

    Re: *HELP* trying to form hyperlinks from XML data


    "S. Brower" <sbrower@walterind.com> wrote:
    FYI I've also tried this
    ![CDATA[<html><a href="mailto:jdoe@nowhere.com">joe</a></html>]]
    with no success.

    >
    >Please help!
    >I would expect the following sample to result in a column titled Email where
    >each entry from the XML file displays as clickable item to send an email.
    > Instead what I get is the stuff in the CDATA tag - verbatim.
    >
    >How do I create the email addresses dynamically?
    >
    >Thanks in advance,
    >SB
    >
    >=============XML FILE======================
    ><?xml version="1.0"?>
    ><employees>
    ><employee EID="1">
    ><Last>Doe</Last>
    ><First>John</First>
    ><Title>Field Representative</Title>
    ><Email><![CDATA["John Doe" <jdoe@nowhere.com>]]></Email>
    ></employee>
    ></employees>
    >
    >
    >===========HTML FILE=================
    ><HTML>
    ><BODY topmargin="1" leftmargin="1" onmousedown="push_me()" onmousemove="window.status
    >= 'Employee Directory'">
    ><XML id=xmldso></XML>
    ><SCRIPT>
    >xmldso.async = false;
    >xmldso.load("eedir.xml");
    >var xmldoc = xmldso.cloneNode(true);
    >
    >function sort(xsldoc){
    > syncChanges();
    > xmldoc.documentElement.transformNodeToObject(xsldoc.documentElement,xmldso.XMLDocument);
    >}
    >
    >function syncChanges(){
    > for (var i=0;i<xmldso.documentElement.childNodes.length;i++)
    > {
    > var currentNode = xmldso.documentElement.childNodes(i).cloneNode(true);
    > var query = "employee[EID = '" + currentNode.childNodes.item(0).text
    >+ "']";
    > var origNode = xmldoc.documentElement.selectSingleNode(query);
    > }
    >}
    ></SCRIPT>
    ><TABLE DATASRC='#xmldso' BORDER CELLPADDING=3>
    > <THEAD>
    > <TH style="font-family: ARIAL; font-size: 8pt">Last</TH>
    > <TH style="font-family: ARIAL; font-size: 8pt">First</TH>
    > <TH style="font-family: ARIAL; font-size: 8pt">Title</TH>
    > <TH style="font-family: ARIAL; font-size: 8pt">Email</TH>
    ></THEAD>
    > <TR>
    > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="Last"></SPAN></TD>
    > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="First"></SPAN></TD>
    > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="Title"></SPAN></TD>
    > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN DATAFLD="Email"></SPAN></TD>
    > </TR>
    ></TABLE>
    ></BODY>
    ></HTML>



  3. #3
    Russell Jones Guest

    Re: *HELP* trying to form hyperlinks from XML data

    You'll either need to change the <Email> nodes in your XML document to look
    like this:

    <Email><a href="mailto:jdoe@nowhere.com">John Doe</a></Email>

    OR

    you'll have to parse the value of the CDATA node in each <Email> element and
    create the anchor tag in your JavaScript code or via XSLT,

    OR (my personal preference)
    You could store the XML data as follows:
    <Email>
    <name>John Doe</name>
    <address>jdoe@nowhere.com</address>
    </Email>

    This last way, you have independent access to the name and the address via
    the DOM or XSL, and you can still create the anchor tag in your JavaScript
    code or via XSLT.

    However, any of these methods should work.

    "S. Brower" <sbrower@walterind.com> wrote in message
    news:3db85884$1@tnews.web.devx.com...
    >
    > "S. Brower" <sbrower@walterind.com> wrote:
    > FYI I've also tried this
    > ![CDATA[<html><a href="mailto:jdoe@nowhere.com">joe</a></html>]]
    > with no success.
    >
    > >
    > >Please help!
    > >I would expect the following sample to result in a column titled Email

    where
    > >each entry from the XML file displays as clickable item to send an email.
    > > Instead what I get is the stuff in the CDATA tag - verbatim.
    > >
    > >How do I create the email addresses dynamically?
    > >
    > >Thanks in advance,
    > >SB
    > >
    > >=============XML FILE======================
    > ><?xml version="1.0"?>
    > ><employees>
    > ><employee EID="1">
    > ><Last>Doe</Last>
    > ><First>John</First>
    > ><Title>Field Representative</Title>
    > ><Email><![CDATA["John Doe" <jdoe@nowhere.com>]]></Email>
    > ></employee>
    > ></employees>
    > >
    > >
    > >===========HTML FILE=================
    > ><HTML>
    > ><BODY topmargin="1" leftmargin="1" onmousedown="push_me()"

    onmousemove="window.status
    > >= 'Employee Directory'">
    > ><XML id=xmldso></XML>
    > ><SCRIPT>
    > >xmldso.async = false;
    > >xmldso.load("eedir.xml");
    > >var xmldoc = xmldso.cloneNode(true);
    > >
    > >function sort(xsldoc){
    > > syncChanges();
    > >

    xmldoc.documentElement.transformNodeToObject(xsldoc.documentElement,xmldso.X
    MLDocument);
    > >}
    > >
    > >function syncChanges(){
    > > for (var i=0;i<xmldso.documentElement.childNodes.length;i++)
    > > {
    > > var currentNode =

    xmldso.documentElement.childNodes(i).cloneNode(true);
    > > var query = "employee[EID = '" + currentNode.childNodes.item(0).text
    > >+ "']";
    > > var origNode = xmldoc.documentElement.selectSingleNode(query);
    > > }
    > >}
    > ></SCRIPT>
    > ><TABLE DATASRC='#xmldso' BORDER CELLPADDING=3>
    > > <THEAD>
    > > <TH style="font-family: ARIAL; font-size: 8pt">Last</TH>
    > > <TH style="font-family: ARIAL; font-size: 8pt">First</TH>
    > > <TH style="font-family: ARIAL; font-size: 8pt">Title</TH>
    > > <TH style="font-family: ARIAL; font-size: 8pt">Email</TH>
    > ></THEAD>
    > > <TR>
    > > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN

    DATAFLD="Last"></SPAN></TD>
    > > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN

    DATAFLD="First"></SPAN></TD>
    > > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN

    DATAFLD="Title"></SPAN></TD>
    > > <TD style="font-family: ARIAL; font-size: 8pt"><SPAN

    DATAFLD="Email"></SPAN></TD>
    > > </TR>
    > ></TABLE>
    > ></BODY>
    > ></HTML>

    >




Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center