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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

getting data from an xml path to javascript

Status
Not open for further replies.

chomp99

IS-IT--Management
Apr 18, 2003
9
0
0
US
Hello,

This might be a fairly easy task but I am having trouble finding a simple description on how to implement this. I have an xml path (has a url and that url is updated on this external file). I want to be able to setup javascript to get that url from that xml path and assign it to a variable so that I can create a second variable that merges the first value with other other values

example:
xml path:
the data in that path is:
<links>
<link name="123" ref="</links>

I want to merge the ref value with other values:
with ?var1=123&var2=abc

final url

Can someone help, I think the main question has to do with just getting the data out of the xml into a javascript variable.

thanks in advance for your help
 
Search on Google.com for xpath javascript, lots of results there
 
To:eek:p
This is how you do it in ie.
[tt]
<script language="javascript">

var surl="var oparser=new ActiveXObject("Msxml2.DomDocument");
oparser.async=false;
oparser.validateOnParse=false;
oparser.load (surl);
if (oparser.parseError.errorCode == 0) {
var onode=oparser.documentElement.selectSingleNode("/links/link") //underlying assumption made here
var sref=onode.getAttribute("ref");
var sname=onode.getAttribute("name");
var shref=sref+"?var1="+sname+"&var2=abc"; [green]//answer[/green]
} else {
var shref=""; //error occurred
}
onode=null;
oparser=null;

</script>
[/tt]
It might be appeared inside a function or some handler.

Different platform, you have to do similar corresponding script.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top