Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

*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>
[2520 byte] By [S. Brower] at [2007-11-9 15:27:02]
# 1 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>
S. Brower at 2007-11-11 23:29:47 >
# 2 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.dev-archive.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>
>
Russell Jones at 2007-11-11 23:30:53 >