I am having trouble fetching a specific value in an XML value using Android XMLPullParser. Here is a snippet of the XML file containing the information I need,
<parameters applicable-location="point1">
<temperature type="apparent" units="Fahrenheit" time-layout="k-p1h-n1-1">
<value>50</value>
</temperature>
<temperature type="dew point" units="Fahrenheit" time-layout="k-p1h-n1-1">
<value>33</value>
</temperature>
I am new to parsing to XML, but I need to retrieve the
<value>
of the:
<temperature type="apparent" units="Fahrenheit" time-layout="k-p1h-n1-1">
Now to me I would just do something like this:
if(xpp.getName().equalsIgnoreCase("temperature") {
xpp.next(); //To bring the parser to that value tag
if(xpp.getName().equalsIgnoreCase("value") {
weather_apparenttemp.setText(xpp.getName());
}
}
But it is not working and I feel I am missing or doing something wrong :( any help? Thanks!
Try this code:
This is for retrieve the tag name
<value>
inside the temperature typed as apparent. If you want to retrieve the value, advance the xpp withxpp.next()
inside the second condition and get the textxpp.getText()
.