Results 1 to 3 of 3
Thread: RSS XML Parsing with XPath
- 10-09-2012, 01:08 AM #1
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
RSS XML Parsing with XPath
Hello all,
I have a method shown below that is failing at the point of the xpath evaluation constructor consisting of (expression, InputSource, qname) -
If I change it out and use the alternate constructor (expression, InputSource) that returns a String, then it works -Java Code:Node node = (Node) xpath.evaluate("//item", is, XPathConstants.NODE);
I just can't seem to get it to return the node, though...Java Code:String node = xpath.evaluate("//item", is);
I'm including the two difference versions of the method below, one that returns the Node (doesn't work) and one with the String(does work):
Java Code:private Node getFeed(String urlToRssFeed, Context context) { try { // setup the url URL url = new URL(urlToRssFeed); XPath xpath = XPathFactory.newInstance().newXPath(); URLConnection con = url.openConnection(); con.setConnectTimeout(15000); con.setReadTimeout(15000); InputSource is = new InputSource(con.getInputStream()); Node node = (Node) xpath.evaluate("//item", is, XPathConstants.NODE); return node; } catch (Exception ee) { Log.d("RyanDebug", ee.getMessage()); return null; } }Java Code:private String getFeed(String urlToRssFeed, Context context) { try { // setup the url URL url = new URL(urlToRssFeed); XPath xpath = XPathFactory.newInstance().newXPath(); URLConnection con = url.openConnection(); con.setConnectTimeout(15000); con.setReadTimeout(15000); InputSource is = new InputSource(con.getInputStream()); String string = xpath.evaluate("//item", is); return string; } catch (Exception ee) { Log.d("RyanDebug", ee.getMessage()); return null; } }
- 10-09-2012, 09:38 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: RSS XML Parsing with XPath
Is the same data being returned each time through the connection?
What happens in the first case if you replace NODE with STRING (and change the cast to a String)?
What happens if you read the data returned in the connection stream and save it as a file, and use a FileInputStream from that instead (which is what I'd do to ensure a consistent test environment)?Please do not ask for code as refusal often offends.
- 10-11-2012, 09:41 PM #3
Member
- Join Date
- Sep 2012
- Posts
- 5
- Rep Power
- 0
Re: RSS XML Parsing with XPath
Thank you for the reply!
Turns out that it was actually working, Eclipse just seems to be acting very oddly. During the debugging session, it would evaluate and then jump to the "return null;" in the exception catch. If you continue on from there, the program acts as if it evaluated "return string;" successfully. Very odd... but it works, anyway.
Similar Threads
-
parsing an xml file and executing an XPATH querry
By fassfouss in forum AndroidReplies: 0Last Post: 04-03-2011, 01:15 AM -
Parsing XML file using Xpath in jdk1.4
By ziggy in forum New To JavaReplies: 7Last Post: 02-27-2011, 12:55 PM -
Problems with parsing using XPath
By thooom in forum XMLReplies: 6Last Post: 04-26-2010, 09:47 AM -
Problems with XPath (XML Parsing)
By thooom in forum New To JavaReplies: 6Last Post: 04-25-2010, 04:56 PM -
How can we write case insensitive queries for Xpath xml parsing
By vijayvcs in forum XMLReplies: 3Last Post: 09-11-2008, 03:00 AM


LinkBack URL
About LinkBacks
Reply With Quote

Bookmarks