/    Sign up×
Community /Pin to ProfileBookmark

hyperlink text from XML with Javascript

Hey people, i’m sorta new to this i’m trying to make a link for some text in an XML from Javascript heres the code i have, what do i need to add to make the link for the ‘title’ field in the XML from the ‘link’ field
i’ve got the XML to display i just need the ‘title’ field to be linked

[CODE]// JavaScript Document

var xmlDoc=null;
if (window.ActiveXObject)
{// code for IE
xmlDoc=new ActiveXObject(“Microsoft.XMLDOM”);
}
else if (document.implementation.createDocument)
{// code for Mozilla, Firefox, Opera, etc.
xmlDoc=document.implementation.createDocument(“”,””,null);
}
else
{
alert(‘Your browser cannot handle this script’);
}
if (xmlDoc!=null)
{
xmlDoc.async=false;

xmlDoc.load(“defencenews/defencenews.xml”);

document.write(“<table border=’1′>”);

var x=xmlDoc.getElementsByTagName(“story”);
for (i=0;i<x.length;i++)
{
document.write(“<tr>”);
document.write(“<td>”);
document.write(
x[i].getElementsByTagName(“title”)[0].childNodes[0].nodeValue);
document.write(“</td>”);

document.write(“<td>”);
document.write(
x[i].getElementsByTagName(“caption”)[0].childNodes[0].nodeValue);
document.write(“</td>”);
document.write(“</tr>”);
}
document.write(“</table>”);
}

[/CODE]

and the XML

[CODE]
<?xml version=”1.0″ encoding=”iso-8859-1″ ?>
– <defencenews>
– <story>
<link>/2008/0331_0406.htm#SydneyCOI”</link>
<title>Title of story</title>
<caption>The caption of the story</caption>
</story>
</defencenews>[/CODE]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@FangApr 15.2008 —  for (i=0;i&lt;x.length;i++) {
document.write('&lt;tr&gt;');
document.write('&lt;td&gt;');
document.write('&lt;a href="'+x[i].getElementsByTagName("link")[0].childNodes[0].nodeValue+'"&gt;'+x[i].getElementsByTagName("title")[0].childNodes[0].nodeValue+'&lt;/a&gt;');
document.write('&lt;/td&gt;');
}
Copy linkTweet thisAlerts:
@RustleauthorApr 16.2008 — Awesome!! thanks mate!

i was even able to apply that logic to add an image!...YAY!!! ?? ? :o ?
×

Success!

Help @Rustle spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.5,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...