473,418 Members | 1,834 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,418 software developers and data experts.

Can you find the bug in <div> I do NOT get sample xml data[bookrss.xml]... RSS Client

Can you find the bug in <div> I do NOT get sample xml data[bookrss.xml]... RSS Client/Server?
I get
xhrequest.readyState == 4 && xhrequest.status == 200 ... 4 & 200 , but no data (local host run)
is this correct
1)var titles = xhrequest.responseXML.getElementsByTagName('title' );
titles[0].firstChild.nodeValue+"</h1>";
2)xml file same folder as .java file in NETBEANS
client
Expand|Select|Wrap|Line Numbers
  1.   <%-- 
  2.     Document   : index
  3.     Created on : Jul 22, 2010, 11:32:20 AM
  4.     Author     : Shop
  5. --%>
  6.  
  7. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  8. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  9.    "http://www.w3.org/TR/html4/loose.dtd">
  10.  
  11. <html>
  12.     <head>
  13.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  14.         <title>JSP Page</title>
  15.  
  16.  
  17.   <script type="text/javascript">
  18. // getxmlhttprequest.js
  19. function getXMLHttpRequest()
  20. {
  21.  var xhrequest = null;
  22.  if(window.XMLHttpRequest)
  23.  {
  24.  // If IE7, Mozilla, Safari, etc: Use native object
  25.   try
  26.   {
  27.    xhrequest = new XMLHttpRequest();
  28.    return xhrequest;
  29.   }
  30.   catch(exception)
  31.   {
  32.   // OK, just carry on looking
  33.   }
  34.  }
  35.  else
  36.  {
  37.  
  38.   // ...otherwise, use the ActiveX control for IE5.x and IE6
  39.    var IEControls = ["MSXML2.XMLHttp.5.0","MSXML2.XMLHttp.4.0","MSXML2.XMLHttp.3.0","MSXML2.XMLHttp"];
  40.    for(var i=0; i<IEControls.length; i++)
  41.    {
  42.     try
  43.     {
  44.      xhrequest = new ActiveXObject(IEControls[i]);
  45.      return xhrequest;
  46.     }
  47.     catch(exception)
  48.     {
  49.      // OK, just carry on looking
  50.     }
  51.    }
  52.   // if we got here we didn�t find and matches
  53.   throw new Error("Cannot create an XMLHttpRequest");
  54.  }
  55. }
  56.  
  57. //processnewsfeed.js
  58. function processRSSFeed()
  59. {
  60.       alert("alert processRSSFeed() "+ xhrequest.readyState + " " + xhrequest.status);
  61.  if(xhrequest.readyState == 4 && xhrequest.status == 200)
  62.  {
  63.        alert("alert readyState/status success processRSSFeed()");
  64.   var titles = xhrequest.responseXML.getElementsByTagName('title');
  65.   var links = xhrequest.responseXML.getElementsByTagName('link');
  66.   var descriptions = xhrequest.responseXML.getElementsByTagName('description');
  67.   var firstItemTitle = "<h1>"+titles[0].firstChild.nodeValue+"></h1>";
  68.   var firstItemLink = "<h3>"+links[0].firstChild.nodeValue+"</h3>";
  69.   var firstItemDescription = "<h3>"+descriptions[0].firstChild.nodeValue+"</h3>";
  70.  
  71.   intro = firstItemTitle+firstItemLink+firstItemDescription;         
  72.   //alert(links[0].firstChild.nodeValue);
  73. for (var i=1; i<=3; i++)            
  74. {
  75.   var firstItemTitle2 = "<p>"+"<h2>"+titles[i].firstChild.nodeValue+"</h2>";
  76.   var firstItemLink2 = "<h3>"+links[i].firstChild.nodeValue+"</h3>";
  77.   var firstItemDescription2 = "<h3>"+descriptions[i].firstChild.nodeValue+"</h3>"+"</p>";   
  78.   total += firstItemTitle2+firstItemLink2+firstItemDescription2+"";
  79.  
  80. }            
  81.  
  82.   document.getElementById("feed").innerHTML=intro+total;
  83.  }
  84. }      
  85.  
  86.  
  87. function ajaxGetRSS()      
  88. {      
  89.   // no 'var', so this is a global variable!
  90.   alert("alert ajaxGetRSS()");
  91.     xhrequest = null;
  92.     try
  93.     {
  94.      xhrequest = getXMLHttpRequest();
  95.     }
  96.     catch(error)
  97.     {
  98.      document.write("Cannot run Ajax code using this browser");
  99.     }
  100.     if(xhrequest != null)
  101.     {
  102.       xhrequest.onreadystatechange = processRSSFeed;
  103.       xhrequest.open("POST", "http://localhost:8084/ParsonsWebServicesAjax/rssfeed", true);
  104.       xhrequest.send(null);
  105.     }
  106. }
  107.  
  108. </script>        
  109.     </head>
  110.     <body>
  111.     <h2>Hello World!</h2>
  112.     <br /><form action="" onsubmit="ajaxGetRSS();">
  113.     <input type="submit" value="Press Appear Data" name="getData" />
  114.     <br /></form>
  115.     <a >click here</a>
  116.     <p>&nbsp;</p>
  117.     <div id="feed"></div>
  118.     </body>
  119. </html>
  120.  
server
Expand|Select|Wrap|Line Numbers
  1.   /*
  2.  * To change this template, choose Tools | Templates
  3.  * and open the template in the editor.
  4.  */
  5.  
  6.  
  7. import java.io.*;
  8. import java.net.*;
  9.  
  10. import javax.servlet.*;
  11. import javax.servlet.http.*;
  12.  
  13. /**
  14.  *
  15.  * @author Shop
  16.  */
  17. public class AjaxRSSServlet extends HttpServlet {
  18.  
  19.     /** 
  20.     * Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
  21.     * @param request servlet request
  22.     * @param response servlet response
  23.     */
  24.     @Override
  25.     protected void doPost(HttpServletRequest request, HttpServletResponse response)
  26.     throws ServletException, IOException {
  27.  
  28.         PrintWriter out = null;
  29.         try {
  30.         response.setContentType("text/xml");
  31.         out = response.getWriter();
  32.  
  33.         File xmlfile = new File("bookrss.xml");
  34.  
  35.         StringBuffer sb = new StringBuffer();
  36.         BufferedReader br = new BufferedReader(new FileReader(xmlfile));
  37.         String s = br.readLine();
  38.         while (s != null)
  39.         {
  40.             sb.append(s.trim());
  41.             s=br.readLine();
  42.  
  43.         }
  44.                 System.out.println(sb);
  45.                 out.print(sb);
  46.         } catch(IOException e) { 
  47.             e.printStackTrace();
  48.             //return null;
  49.         }
  50.         //return null;
  51.     } 
  52.  
  53.  
  54. }
  55.  
  56. bookrss.xml   // version is correct?
  57.  
  58. <rss version="0.91"> 
  59. <channel> 
  60. <title>hT</title> 
  61. <link>hL</link> 
  62. <description>hD</description> 
  63. <item> 
  64. <title>hT1</title> 
  65. <link>hL1</link> 
  66. <description>hD1</description> 
  67. </item> 
  68. <item> 
  69. <title>hT2</title> 
  70. <link>hL2</link> 
  71. <description>hD2</description> 
  72. </item> 
  73. <item> 
  74. <title>hT3</title> 
  75. <link>hL3</link> 
  76. <description>hD3</description> 
  77. </item> 
  78. </channel> 
  79. </rss> 
  80.  
Aug 14 '10 #1
0 1011

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Philo | last post by:
How do I select all <div> tags except those which contain a <table> tag somewhere within them? Example XML: <********************** sample input ***********************> <txtSectionBody>...
1
by: Xah Lee | last post by:
with strict HTML spec, can one have <p> tags inside table's <td> tag? also, in strict XHTML, can one have <p> tages inside <div>? Thanks. Xah xah@xahlee.org ∑ http://xahlee.org/
23
by: Mikko Ohtamaa | last post by:
From XML specification: The representation of an empty element is either a start-tag immediately followed by an end-tag, or an empty-element tag. (This means that <foo></foo> is equal to...
61
by: Toby Austin | last post by:
I'm trying to replace <table>s with <div>s as much as possible. However, I can't figure out how to do the following… <table> <tr> <td valign="top" width="100%">some data that will...
8
by: slim | last post by:
hi again all, i am still working on the website as mentioned in earlier threads and have hit another snag... http://awash.demon.co.uk/index.php http://awash.demon.co.uk/vd.css the php is...
44
by: Jim M | last post by:
I have had great success with using <iframe> with overflow-y set to auto. I can get a similar look with the <iframe> tag. BUT... In all cases I need to have fixed heights. Is there a way to...
9
by: Julia Briggs | last post by:
How do I construct a <iframe> or equivalent for FireFox/NS browsers, inside a screen centered <div> tag? Can it be done?
7
by: pamelafluente | last post by:
The precious input given by Laurent, Martin, Benjamin about XMLHttpRequest in Javascript, has made me think that perhaps I could improve what I am currently doing by using Ajax. Let's make it...
28
by: Kent Feiler | last post by:
1. Here's some html from a W3C recommendations page. <P>aaaaaaaaa<DIV>bbbbbbbbb</DIV><DIV>cccccccc<P>dddddddd</DIV> 2.Although I didn't think it would make any difference, I tried it with the...
10
by: Summercoolness | last post by:
so i am starting to use more of <br /and <div style="clear: both" / which is the XHTML style... now, won't those actually confuse the old browsers? for example, will the old browser treat the...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.