I'm currently working for the first time with API's and are having some trouble retrieving data.
The xml file looks like this:
<schedule>
...
<scheduledepisode>
<episodeid>22441</episodeid>
<title>Ekonyheter </title>
<starttimeutc>2012-09-19T04:00:00Z</starttimeutc>
<endtimeutc>2012-09-19T04:03:00Z</endtimeutc>
<program id="83" name="Ekot" />
<channel id="164" name="P3" />
</scheduledepisode>
<scheduledepisode>
So i used NodeList nodelist1 = doc.getElementsByTagName("scheduledepisode");
to get all the scheduledepisode
elements, then I thought that to revive the data under title I could simple use the following:
System.out.println(node.getAttributes().getNamedItem("title").getTextContent());
However this only returns null and i cant understand why, can someone explain what I am missing here. To my understanding the title element is a attribute to the scheduledepisode
element. Is that wrong?
The length of the nodelist is correct contra the amount of scheduledepisodes
so I'm assuming that I have gotten the correct elements.
The code looks like this:
NodeList nodelist1 = doc.getElementsByTagName("scheduledepisode");
for (int i = 0; i < nodelist1.getLength(); i++)
{
Node node = nodelist1.item(i);
if (node.getNodeType() == Node.ELEMENT_NODE )
{
if (node.getAttributes().getNamedItem("title") != null) {
System.out.println(node.getAttributes().getNamedItem("title").getTextContent());
}
}
}