Getting the value of an attribute in Java from a XML using XPath

Alogretle

New Member
I'm currently using XPath to get some information from a podcast feed using Java and XPath. I'm trying to read the attribute of a node: \[code\]<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sy="http://purl.org/rss/1.0/modules/syndication/" xmlns:admin="http://webns.net/mvcb/" xmlns:atom="http://www.w3.org/2005/Atom/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" version="2.0"> <channel> [....] <itunes:image href="http://icebox.5by5.tv/images/broadcasts/14/cover.jpg" />[...]\[/code\]I want to get the value of the \[code\]href\[/code\] attribute in <itunes:image>. Currently, I'm using the following code:\[code\]private static String IMAGE_XPATH = "//channel/itunes:image/@href";String imageUrl = xpath.compile(IMAGE_XPATH).evaluate(doc, XPathConstants.STRING).toString();\[/code\]The result of imageUrl is null. What happens in the code? Do I have an error in the XPath code, or in the Java code?Thanks! :)
 
Back
Top