I need to get the attribute url
of all the elements <media:content/>
of an XML similar to this.
<rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'>
<channel>
<item>
<media:group>
<media:content url='https://valor'/>
</media:group>
</item>
<item>
<media:group>
<media:content url='https://valor'/>
</media:group>
</item>
</channel>
</rss>
This is a method I tried, but it contents.getLength()
returns zero.
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(inputStream);
NodeList contents = doc.getElementsByTagNameNS("http://search.yahoo.com/mrss/", "content");
I've tried using XPath... again it contents.getLength()
returns zero.
XPathFactory factory2 = XPathFactory.newInstance();
XPath xpath = factory2.newXPath();
// XPathExpression expr = xpath.compile("//content");
XPathExpression expr = xpath.compile("//*[name()='content']");
NodeList contents = (NodeList) expr.evaluate(doc, XPathConstants.NODESET);
I never get the required nodes, any suggestions?