這篇文章將為大家詳細(xì)講解有關(guān)解析rss問(wèn)題的示例分析,小編覺(jué)得挺實(shí)用的,因此分享給大家做個(gè)參考,希望大家閱讀完這篇文章后可以有所收獲。
十多年的郎溪網(wǎng)站建設(shè)經(jīng)驗(yàn),針對(duì)設(shè)計(jì)、前端、開(kāi)發(fā)、售后、文案、推廣等六對(duì)一服務(wù),響應(yīng)快,48小時(shí)及時(shí)工作處理。成都全網(wǎng)營(yíng)銷推廣的優(yōu)勢(shì)是能夠根據(jù)用戶設(shè)備顯示端的尺寸不同,自動(dòng)調(diào)整郎溪建站的顯示方式,使網(wǎng)站能夠適用不同顯示終端,在瀏覽器中調(diào)整網(wǎng)站的寬度,無(wú)論在任何一種瀏覽器上瀏覽網(wǎng)站,都能展現(xiàn)優(yōu)雅布局與設(shè)計(jì),從而大程度地提升瀏覽體驗(yàn)。創(chuàng)新互聯(lián)建站從事“郎溪網(wǎng)站設(shè)計(jì)”,“郎溪網(wǎng)站推廣”以來(lái),每個(gè)客戶項(xiàng)目都認(rèn)真落實(shí)執(zhí)行。
try{ org.dom4j.io.SAXReader saxReader = new org.dom4j.io.SAXReader(); org.dom4j.Document document = saxReader.read(rssUrl); org.dom4j.Element channel = (org.dom4j.Element) document.getRootElement().element("channel"); int index =0; for (java.util.Iterator i = channel.elementIterator("item"); i.hasNext();){ if(index+1>rssTable.Rows.length){ break; } org.dom4j.Element element = (org.dom4j.Element) i.next(); String title = element.elementText("title"); String link = element.elementText("link"); String pubDate = element.elementText("pubDate"); String source = element.elementText("source"); ci.adp.DataRow rssRow = rssTable.getDataRowByIndex(index); rssRow.setValue("TITLE", title); rssRow.setValue("LINK", link); rssRow.setValue("PUBDATE", pubDate); rssRow.setValue("SOURCE", source); /* System.out.println("title標(biāo)題: " + title); System.out.println("link鏈接: " + link); System.out.println("pubDate發(fā)布時(shí)間: " +pubDate); System.out.println("source來(lái)源: " + source); */ index++; } }catch (Exception e) { e.printStackTrace(); }
折騰了一上午,終于換一種方式搞定了。
上面這種dom4j方式,在我本機(jī)環(huán)境(windows+weblogic10+jdk1.6)下沒(méi)問(wèn)題,
放到服務(wù)器上(linux5.4 x64+weblogic10+jdk1.6)上,始終都報(bào)這個(gè)錯(cuò):
[oracle@ablw010215 bin]$ Warning: Caught exception attempting to use SAX to load a SAX XMLReader Warning: Exception was: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration Warning: I will print the stack trace then carry on using the default SAX parser java.lang.ClassCastException: com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration at org.xml.sax.helpers.XMLReaderFactory.loadClass(XMLReaderFactory.java:199) at org.xml.sax.helpers.XMLReaderFactory.createXMLReader(XMLReaderFactory.java:150) at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:83) at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894) at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715) at org.dom4j.io.SAXReader.read(SAXReader.java:435) at org.dom4j.io.SAXReader.read(SAXReader.java:321) at jsp_servlet._ajax._comm._bbs.__iframearticlecontent._jspService(__iframearticlecontent.java:100) at weblogic.servlet.jsp.JspBase.service(JspBase.java:35) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at ci.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:178) org.dom4j.DocumentException: SAX2 driver class weblogic.xml.jaxp.RegistryXMLReader does not implement XMLReader Nested exception: SAX2 driver class weblogic.xml.jaxp.RegistryXMLReader does not implement XMLReader at org.dom4j.io.SAXReader.read(SAXReader.java:484) at org.dom4j.io.SAXReader.read(SAXReader.java:321) at jsp_servlet._ajax._comm._bbs.__iframearticlecontent._jspService(__iframearticlecontent.java:99) at weblogic.servlet.jsp.JspBase.service(JspBase.java:35) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at ci.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:178) Nested exception: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:98) at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894) at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715) at org.dom4j.io.SAXReader.read(SAXReader.java:435) at org.dom4j.io.SAXReader.read(SAXReader.java:321) at jsp_servlet._ajax._comm._bbs.__iframearticlecontent._jspService(__iframearticlecontent.java:100) at weblogic.servlet.jsp.JspBase.service(JspBase.java:35) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at ci.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:178) Nested exception: java.lang.ClassCastException: com.sun.org.apache.xerces.internal.parsers.XIncludeAwareParserConfiguration at org.dom4j.io.SAXHelper.createXMLReader(SAXHelper.java:98) at org.dom4j.io.SAXReader.createXMLReader(SAXReader.java:894) at org.dom4j.io.SAXReader.getXMLReader(SAXReader.java:715) at org.dom4j.io.SAXReader.read(SAXReader.java:435) at org.dom4j.io.SAXReader.read(SAXReader.java:321) at jsp_servlet._ajax._comm._bbs.__iframearticlecontent._jspService(__iframearticlecontent.java:100) at weblogic.servlet.jsp.JspBase.service(JspBase.java:35) at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:227) at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:125) at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:300) at weblogic.servlet.internal.TailFilter.doFilter(TailFilter.java:27) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at ci.filter.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:107) at weblogic.servlet.internal.FilterChainImpl.doFilter(FilterChainImpl.java:57) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.wrapRun(WebAppServletContext.java:3715) at weblogic.servlet.internal.WebAppServletContext$ServletInvocationAction.run(WebAppServletContext.java:3681) at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321) at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120) at weblogic.servlet.internal.WebAppServletContext.securedExecute(WebAppServletContext.java:2277) at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2183) at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1454) at weblogic.work.ExecuteThread.execute(ExecuteThread.java:209) at weblogic.work.ExecuteThread.run(ExecuteThread.java:178)
<2012-11-8 上午10時(shí)56分08秒 CST>
<2012-11-8 上午10時(shí)56分08秒 CST>
在weblogic.xml加配置文件、加lib包等等都不起作用,換成這個(gè)就好了(依賴lib在我上傳的資源中,完全免費(fèi)):
try { URL url = new URL(rss); // 讀取Rss源 XmlReader reader = new XmlReader(url); System.out.println("Rss源的編碼格式為:" + reader.getEncoding()); SyndFeedInput input = new SyndFeedInput(); SyndFeed feed = input.build(reader); // 得到SyndFeed對(duì)象,即得到Rss源里的所有信息 List entries = feed.getEntries(); // 得到Rss新聞中子項(xiàng)列表 int index =0; for (int i = 0; i < entries.size(); i++) { // 循環(huán)得到每個(gè)子項(xiàng)信息 if(index+1>rssTable.Rows.length){ break; } SyndEntry entry = (SyndEntry) entries.get(i); /* System.out.println("標(biāo)題:" + entry.getTitle()); System.out.println("連接地址:" + entry.getLink()); SyndContent description = entry.getDescription(); System.out.println("標(biāo)題簡(jiǎn)介:" + description.getValue()); System.out.println("發(fā)布時(shí)間:" + entry.getPublishedDate()); // 以下是Rss源可先的幾個(gè)部分 System.out.println("標(biāo)題的作者:" + entry.getAuthor()); */ ci.adp.DataRow rssRow = rssTable.getDataRowByIndex(index); rssRow.setValue("TITLE", entry.getTitle()); rssRow.setValue("LINK", entry.getLink()); rssRow.setValue("PUBDATE", entry.getPublishedDate()); rssRow.setValue("SOURCE", entry.getAuthor()); /* // 此標(biāo)題所屬的范疇 List categoryList = entry.getCategories(); if (categoryList != null) { for (int m = 0; m < categoryList.size(); m++) { SyndCategory category = (SyndCategory) categoryList .get(m); System.out.println("此標(biāo)題所屬的范疇:" + category.getName()); } } */ index++; /* // 得到流媒體播放文件的信息列表 List enclosureList = entry.getEnclosures(); if (enclosureList != null) { for (int n = 0; n < enclosureList.size(); n++) { SyndEnclosure enclosure = (SyndEnclosure) enclosureList .get(n); System.out.println("流媒體播放文件:" + entry.getEnclosures()); } } */ } } catch (Exception e) { e.printStackTrace(); }
org.dom4j.io.SAXReader saxReader = new org.dom4j.io.SAXReader();org.dom4j.Document document = saxReader.read(rssUrl);org.dom4j.Element channel = (org.dom4j.Element) document.getRootElement().element("channel"); int index =0; for (java.util.Iterator i = channel.elementIterator("item"); i.hasNext();){ if(index+1>rssTable.Rows.length){ break; } org.dom4j.Element element = (org.dom4j.Element) i.next(); String title = element.elementText("title"); String link = element.elementText("link"); String pubDate = element.elementText("pubDate"); String source = element.elementText("source"); ci.adp.DataRow rssRow = rssTable.getDataRowByIndex(index); rssRow.setValue("TITLE", title); rssRow.setValue("LINK", link); rssRow.setValue("PUBDATE", pubDate); rssRow.setValue("SOURCE", source); /* System.out.println("title標(biāo)題: " + title); System.out.println("link鏈接: " + link); System.out.println("pubDate發(fā)布時(shí)間: " +pubDate); System.out.println("source來(lái)源: " + source); */ index++; }
關(guān)于“解析rss問(wèn)題的示例分析”這篇文章就分享到這里了,希望以上內(nèi)容可以對(duì)大家有一定的幫助,使各位可以學(xué)到更多知識(shí),如果覺(jué)得文章不錯(cuò),請(qǐng)把它分享出去讓更多的人看到。