Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Linking the contents og an XML tag

Status
Not open for further replies.

trent101

Programmer
Nov 4, 2005
50
AU
Hey,

Ok, I am parsing a XML file into a HTML doc using javascript. At the moment my javascriptlooks like this ->

---------------------------------------------------------
<script type="text/javascript">
var xmlDoc
function loadXML()
{
//load the rfid xml file for Internet Explorer
if (window.ActiveXObject)
{
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async=false;
xmlDoc.load("sample.xml");
getmessage()
}
// load the rfid xml file for Mozilla
else if (document.implementation && document.implementation.createDocument)
{
xmlDoc= document.implementation.createDocument("","",null);
xmlDoc.load("xmlDoc.onload=getmessage
}
else
{
alert('Your browser does not support this script');
}
}
function getmessage()
{
// Load the first four articles titles
document.getElementById("title1").innerHTML=xmlDoc.getElementsByTagName("title")[1].firstChild.nodeValue
document.getElementById("link1").innerHTML=xmlDoc.getElementsByTagName("link")[1].firstChild.nodeValue

</script>

--------------------------------------------------

And, within my body tag, I display the contents of the title field like this ->

-------------------------------

<span id="title1"></span>

-----------------------------------

Now this works fine, the data inside the title tag gets displayed on the screen. However, There is another tag under the title tag in the xml document that contains a link for a web address. What I want is the text that is outputted from the title tag to link to the web address thats in the link tag.

I have tried using the id "link1" is a href and many similar ways but it wont work. Im not sure if this is possible via html or whether I need javascript to do it.

Any help is much appreciated.

Thanks for your time.

Now I have tried
 
What I am intrigued is that you show the id="title1" part which is working and that you have no intention to show the id="link1" part which is not working, or sort of. Is it that members who can devine what it is in order to qualify to answer the question?

 
>What I want is the text that is outputted [blue]from the title tag to link[/blue] to the web address thats in the link tag.

Just guessing on your span and link.
[tt]
function getmessage() {
var s;
// Load the first four articles titles - ???
s=xmlDoc.getElementsByTagName("title")[1].firstChild.nodeValue;
document.getElementById("title1").innerHTML=s;
document.getElementById("link1").href=s;
s=xmlDoc.getElementsByTagName("link")[1].firstChild.nodeValue;
document.getElementById("link1").innerHTML=s;
}
[/tt]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top