Forum Moderators: open

Message Too Old, No Replies

XML to Javascript variable or display a link?

its probably somthing obvious....

         

trevor26

8:02 am on Nov 25, 2004 (gmt 0)

10+ Year Member



XML to Javascript variable or display a link?

I know how to display XML data in an html page in 2 ways as shown below, but how do i display a link from the XML file data?

If i could get a field from the XML into a variable that would be enough, and could also be useful for other things.

<xml src="article26.xml" id="powart" async="false"></xml>
<span datasrc="#powart" datafld="TITLE"></span>
(or use DIV tags)

OR:

<script type="text/javascript" for="window" event="onload">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("article26.xml")
nodes=xmlDoc.documentElement.childNodes
title.innerText= nodes.item(0).text
</script>
</head>
<body>
<span id="title"> </span>
</body>
</html>

DrDoc

7:17 pm on Nov 26, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld! [WebmasterWorld.com]

how do i display a link from the XML file data

Not quite sure I know what you mean by that...
Then again, I usually never use JavaScript for loading XML...

trevor26

2:06 am on Nov 27, 2004 (gmt 0)

10+ Year Member



OK to clarify,
lets say I have an XML doc with a list of URLs and descriptions.
How can I use javascript to display it making the URLs proper links?
I can display them as text using the above examples but thats no good.

Thanks,
Trevor

Crustov

3:17 am on Nov 27, 2004 (gmt 0)

10+ Year Member



Are you looking to do something like this?

<script type="text/javascript" for="window" event="onload">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false";
xmlDoc.load("list.xml") ;
nodes=xmlDoc.documentElement.childNodes;
document.write("<a href='" + (nodes.item(0).text) + "'>" + (nodes.item(0).text) + "</a>");
</script>

trevor26

5:23 am on Nov 27, 2004 (gmt 0)

10+ Year Member



Yea thats perfect thanks!

And I can use:

var price=(nodes.item(1).text)

to get a field into a string.

Thank You!