Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Professional For advanced coder questions in ASP 3. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old December 18th, 2007, 06:33 PM
Banned
Points: 1,561, Level: 16
Points: 1,561, Level: 16 Points: 1,561, Level: 16 Points: 1,561, Level: 16
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jul 2005
Location: , , .
Posts: 317
Thanks: 0
Thanked 0 Times in 0 Posts
Default Problems parsing XML Feed in Javascript

I was initially looking for a solution to parse a remote XML feed into an ASP.NET page using JavaScript, and the code below displays a solution.

The code in this thread works great at pulling nodes from an external XML feed. I have an internal client-side "news scroller" script (JavaScript) that I want to display some of the nodes from the server-side code.

So can I pull XML nodes from an external XML feed, declare variables from that code, and then use those server-side variables within client-side code?

Something like this:
Code:
<%@ LANGUAGE="JAVASCRIPT" %>
<%
    var xmlDoc;
    xmlDoc = new ActiveXObject("Msxml2.DOMDocument.3.0")
    xmlDoc.async=false;
    xmlDoc.setProperty("ServerHTTPRequest", true) 


    if (xmlDoc.load("http://codeamber.org/a1xl04act/amberalert.xml") == false)
    {
        Response.Write("Failed to load xml");
    }
var amberDescription = xmlDoc.selectSingleNode("//FullText").text;//<<----CAN I PULL THIS INTO CLIENT-SIDE CODE???

%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <title>Pull XML  Feed</title>
<script type="text/javascript" language="javascript">
var pausecontent=new Array()

//These need to be dynamically pulled from existing XML feeds:
pausecontent[0]='<strong><a href="amberalert.aspx">Amber Alert:</a></strong> ' + amberDescription + ' <a href="amberdetails.aspx">Learn more #62;#62;</a>'
pausecontent[1]='<strong><a href="anotherfeed.aspx">Another Feed:</a></strong> ' + anotherfeedDescription + ' <a href="anotherfeed.aspx">Learn more #62;#62;</a>'
//.....MORE JS CODE GOES HERE TO CREATE THE ACTUAL SCROLLER...
}
</script>
</head>
<body>
    <h1>Pull XML Feed</h1>
    <p><b>Alertstatus:</b> <span id="Alertstatus"><%=xmlDoc.selectSingleNode("//Alertstatus").text %></span><br />
    <b>FullText:</b> <span id="FullText"><%=xmlDoc.selectSingleNode("//FullText").text %></span><br />
    <b>Alertinfo:</b> <span id="Alertinfo"></span><br />
    <b>AlertState:</b> <span id="AlertState"><%=xmlDoc.selectSingleNode("//Alertinfo/@states").text %></span><br />
    <b>Victim:</b> <span id="Victim"><%=xmlDoc.selectSingleNode("//Victim/@name").text %></span>
    </p>
    <script type="text/javascript">
        new pausescroller(pausecontent, "scroller", "someclass", 8000)
    </script>
</body>
</html>
I don't know much about using client-side code in conjunction with server-side code, so if anyone can let me know if this is possible, that would be great. Thanks.

KWilliams


Similar Threads
Thread Thread Starter Forum Replies Last Post
ASP.NET XML Feed Error kwilliams ASP.NET 2.0 Professional 0 February 19th, 2008 05:41 PM
Problems parsing XML Feed in Javascript kwilliams Javascript 1 November 7th, 2007 05:59 PM
Parsing XML with Javascript rvanandel Javascript How-To 2 August 29th, 2005 09:37 AM
xml feed with javascript jon8884 Javascript 5 June 22nd, 2005 01:15 PM
XML news feed sankar XML 1 December 17th, 2003 05:28 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.