Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Disable namespace awarness:</p> <pre><code>DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance(); xmlFact.setNamespaceAware(false); </code></pre> <p>Your xpath expression should look like this now:</p> <pre><code>"//channel/image/@href" </code></pre> <p>If you need to use it as namespace aware, just implement your own <a href="http://docs.oracle.com/javase/1.5.0/docs/api/javax/xml/namespace/NamespaceContext.html#getPrefix%28java.lang.String%29" rel="nofollow">NameSpaceContext</a>, should look like this:</p> <pre><code>NamespaceContext ctx = new ItunesNamespaceContext(); XPathFactory xpathFact = XPathFactory.newInstance(); XPath xpath = xpathFact.newXPath(); xpath.setNamespaceContext(ctx); String IMAGE_XPATH = "//channel/itunes:image/@href"; String imageUrl = path.compile(IMAGE_XPATH).evaluate(doc,XPathConstants.STRING).toString(); </code></pre> <p>EDIT: Here is a test code that proves my point:</p> <pre><code>String a ="&lt;?xml version=\"1.0\" encoding=\"UTF-8\"?&gt;&lt;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\"&gt;&lt;channel&gt;&lt;itunes:image href=\"http://icebox.5by5.tv/images/broadcasts/14/cover.jpg\" /&gt;&lt;/channel&gt;&lt;/rss&gt;"; DocumentBuilderFactory xmlFact = DocumentBuilderFactory.newInstance(); xmlFact.setNamespaceAware(false); DocumentBuilder builder = xmlFact.newDocumentBuilder(); XPathFactory xpathFactory = XPathFactory.newInstance(); String expr = "//channel/image/@href"; XPath xpath = xpathFactory.newXPath(); Document doc = builder.parse(new InputSource(new StringReader(a))); String imageUrl = (String) xpath.compile(expr).evaluate(doc ,XPathConstants.STRING); System.out.println(imageUrl); </code></pre> <p>The output is:</p> <pre><code>http://icebox.5by5.tv/images/broadcasts/14/cover.jpg </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload