I want to read rss from another web. but I can't read rss . I use Netbeans and I add JSTL Library already. I can use forEach tag but every time when I use xml tag it show error. This is my code for read rss. I don't know how to read rss with JSTL tag please help me.
<!-- Filename: ShowStudents.jsp -->
<%@taglib uri="http://java.sun.com/jsp/jstl/xml" prefix="x"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<HTML>
<BODY>
<c:import var="xmlDoc" url="http://www.manager.co.th/RSS/Home/Breakingnews.xml"/>
<x:parse var="parsedDocument" xml="${xmlDoc}"/>
<table>
<tr>
<th>Title : </th>
<th>Link : </th>
</tr>
<x:forEach select="$parsedDocument/channel/item"> // This code I ever been change to $parsedDocument/rss/channel/ and $parsedDocument/rss/channel/title ,but it show same error.
<tr>
<td> <x:out select="title" /> </td>
<td> <x:out select="link" /> </td>
</tr>
</x:forEach>
</table>
</BODY>
</HTML>
when I run this code it show error like this. how to read rss with JSTL tag please help me.
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jasper.JasperException: javax.servlet.ServletException: javax.servlet.jsp.JspException: org.xml.sax.SAXParseException: Content is not allowed in prolog. org.apache.jasper.servlet.JspServletWrapper.handleJspException(JspServletWrapper.java:527) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:401) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) Filter.ThaiRequest.doFilter(ThaiRequest.java:38) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
javax.servlet.ServletException: javax.servlet.jsp.JspException: org.xml.sax.SAXParseException: Content is not allowed in prolog. org.apache.jasper.runtime.PageContextImpl.doHandlePageException(PageContextImpl.java:858) org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:791) org.apache.jsp.test_jsp._jspService(test_jsp.java:101) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) Filter.ThaiRequest.doFilter(ThaiRequest.java:38) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
root cause
org.xml.sax.SAXParseException: Content is not allowed in prolog. com.sun.org.apache.xerces.internal.parsers.DOMParser.parse(DOMParser.java:249) com.sun.org.apache.xerces.internal.jaxp.DocumentBuilderImpl.parse(DocumentBuilderImpl.java:284) org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseInputSource(ParseSupport.java:227) org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseInputSourceWithFilter(ParseSupport.java:193) org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseReaderWithFilter(ParseSupport.java:199) org.apache.taglibs.standard.tag.common.xml.ParseSupport.parseStringWithFilter(ParseSupport.java:206) org.apache.taglibs.standard.tag.common.xml.ParseSupport.doEndTag(ParseSupport.java:138) org.apache.jsp.test_jsp._jspx_meth_x_005fparse_005f0(test_jsp.java:150) org.apache.jsp.test_jsp._jspService(test_jsp.java:80) org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:377) org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) javax.servlet.http.HttpServlet.service(HttpServlet.java:717) Filter.ThaiRequest.doFilter(ThaiRequest.java:38) org.netbeans.modules.web.monitor.server.MonitorFilter.doFilter(MonitorFilter.java:393)
Update:
Now I can read xml with JDOM in servlet but I can't display in jsp file. I can display all data from xml in servlet. I don't know how to display data from title and link tag only in jsp file. please help me.
try {
ReadXMLFile rxml = new ReadXMLFile();
NodeList nodes = (NodeList) rxml.readXML();
for (int i = 0; i < nodes.getLength(); i++) {
/* I can display all data from xml. I want to display data from title and link tag only in JSP file. */
System.out.println(nodes.item(i).getNodeValue());
}