XmlPullParser
seems to have the ability to be namespace aware, the difference is it has to be explicitly set. Per the documentation of XmlPullParseFactory#setNamespaceAware
:
Specifies that the parser produced by this factory will provide support for XML namespaces. By default the value of this is set to false.
You might want to try that option.
Also, as mentioned in the comments I have tried to traverse through your xml with DOM with zero issues, below is the source code of printing all the duration values (just to let you know, this is to be run as a Java
program and not within the ADT
):
public static void main(String[] args) throws ParserConfigurationException,
SAXException, IOException {
InputStream path = new URL(
"https://gdata.youtube.com/feeds/api/standardfeeds/top_rated")
.openStream();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(path);
traverse(document.getDocumentElement());
}
public static void traverse(Node node) {
NodeList list = node.getChildNodes();
for (int i = 0; i < list.getLength(); i++) {
Node currentNode = list.item(i);
traverse(currentNode);
}
if (node.getNodeName().equals("yt:duration")) {
Element durationElement = (Element) node;
System.out.println(durationElement.getAttribute("seconds"));
}
}
Output I get:
56
361
225
265
219
220
259
267
376
205
127
308
249
17
162
220
183
298
172
267
204
209
I always prefer recursion (as above) with DOM
as it simplifies the full traversal thereby providing the flexibility too.
If you want to know more about grouping these elements together, you can refer to my post here as well.