Java Reference
In-Depth Information
public void characters(KXmlParser parser) {
if (buffer != null)
buffer.append(parser.getText());
}
public void endElement(KXmlParser parser) {
String qName = parser.getName();
if (qName.equals(Location.XML_TAG_SPEED) == 0) {
windSpeed = buffer.toString();
}
if (qName.equals(Location.XML_TAG_DIRECTION) == 0) {
windDirection = buffer.toString();
}
if (qName.equals(Location.XML_TAG_WIND) == 0) {
location.setWind(windSpeed, windDirection);
}
if (qName.equals(Location.XML_TAG_PRECIP) == 0) {
precipitation = buffer.toString();
location.setPrecipitation(precipitation,precipProb,precipType);
}
if (qName.equals(Location.XML_TAG_TEMP) == 0 && setTemp )
{
location.setTemperature(buffer.toString());
}
if (qName.equals(Location.XML_TAG_WHEN) == 0 && setForecast) {
location.setForecast( buffer.toString());
}
}
public void endDocument(KXmlParser parser) {
}
}
The code to LocationParser is very similar to LocationParserHandler , and for good
reason: it's parsing the same XML, and once you obtain events from an XML parser, it
makes little difference whether the parser is a pull or push parser, as long as you can han-
dle the events. Like LocationParserHandler , LocationParser uses a Location object and
some temporary variables to store intermediate state while parsing a document.
 
Search WWH ::




Custom Search