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

redirect a page

Status
Not open for further replies.

Kazzy

Programmer
Jul 21, 2003
20
US
Hello Everyone, I am very new to xml...I am have about 500 xml files like fileOne and fileTwo below..They have same schema. Some
of the file only contains a website in the <item-content> as you can see i fileOne. The other contains html with in xml...What I am
tryin to do is when I click in one of the links in other pages. It calls the asp page below and the content gets display. This works just fine.
However, I need to be able to redirect the page if the value of <item-content> is a web addresss. Otherwise,I just need display the content.


---asp page

<script type="text/javascript">
var tempItem
tempItem = " items/" + displayItem('item')

var strResponse
var xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
xmlhttp.open("GET", tempItem, false);
xmlhttp.send();
xmlhttp.responseText;

document.write(xmlhttp.responseText);
<script>


-----xml file One

<?xml version="1.0"?>
<LIFE>
<item>
<item-id>12162</item-id>
<item-content></item>
</LIFE>



-----xml file Two

<?xml version="1.0"?>
<LIFE><item>
<item-id>12082</item-id>
<item-content>
<html>
<head>
<title>Reasons to Stop Smoking</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body bgcolor="#FFFFFF" text="#000000">
<h4><font face="Arial, Helvetica, sans-serif" color="#324987"> Reasons to Stop
Smoking</font></h4>
<p><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">There are
a lot of good reasons to stop smoking. Here are just a few to help you get started.</font></p>
<ul><font color="189B6F">
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Bad breath
and stained teeth </font></li>
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Bad smell
in clothes and hair and on skin <br>
</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Decreased
athletic ability <br>
</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Cough
and sore throat <br>
</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Faster
heartbeat and raised blood pressure <br>
</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Risk of
passive smoking to people around you <br>
</font></li>
<li><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Cost of
cigarettes</font></li>
</font></ul>
<p><font face="Arial, Helvetica, sans-serif" size="2" color="189B6F">Check out
our <b>StayQuit</b> stop smoking program to learn more. </font></p>
<p>? </p>
</body>
</html>
</item-content>
</item>
</LIFE>
 
use XPath to check for...

"//item-content/html"

If it returns blank, nothing, null, ect... then navigate to the URL...
Otherwise, Navigate to "about:blank" and document.write the page...

Something Like...
Code:
<script type="text/javascript">
var xmlDoc=new ActiveXObject("Microsoft.XMLDOM")
xmlDoc.async="false"
xmlDoc.load("somefile.xml")
[b]if(xmlDoc.selectSingleNode("//item-content/html") != null)
  document.write(xmlDoc.documentElement.xml);
else
  navigate(xmlDoc.selectSingleNode("//item-content").text());[/b]
</script>

hope this helps...

Visit My Site
PROGRAMMER: (n) Red-eyed, mumbling mammal capable of conversing with inanimate objects.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top