我正在开发一种应用方法,其中我的一个单元是天气预报。 我正在使用SAX Parser,截至现在,我正在整理XML档案,并获得一个地方的成果。
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.saxmain);
ScrollView MyScrollView = new ScrollView(this);
LinearLayout layout = new LinearLayout(this);
layout.setOrientation(LinearLayout.VERTICAL);
MyScrollView.addView(layout);
try {
/** Handling XML */
SAXParserFactory spf = SAXParserFactory.newInstance();
SAXParser sp = spf.newSAXParser();
XMLReader xr = sp.getXMLReader();
/** Send URL to parse XML Tags */
URL sourceUrl = new URL(
"http://192.168.1.31:81/Udayavani/android/weather/weather.php?city=mumbai");
/** Create handler to handle XML Tags ( extends DefaultHandler ) */
MyXMLHandler myXMLHandler = new MyXMLHandler();
xr.setContentHandler(myXMLHandler);
xr.parse(new InputSource(sourceUrl.openStream()));
} catch (Exception e) {
System.out.println("XML Pasing Excpetion = " + e);
}
/* Get result from MyXMLHandler TagList Object */
taglist = MyXMLHandler.sitesList;
for (int i = 0; i <26; i++) {
texts[i] = new TextView(this);
texts[i].setText(""+i);
texts[i].setTypeface(kannada);
layout.addView(texts[i]);
}
/** Set the result text in textview and add it to layout */
texts[0].setText("Current= "+taglist.getCurrent().get(0));
texts[1].setText("Temp= "+taglist.getTemp().get(0));
texts[2].setText("Humidity= "+taglist.getHumidity().get(0));
texts[3].setText(""+taglist.getWind_condition().get(0));
texts[4].setText(""+taglist.getIcon().get(0));
int j=0;
int k=5;
while(k<20){
texts[k].setText("----------------------------------");
k++;
texts[k].setText("Day= "+taglist.getDay().get(j));
k++;
texts[k].setText("Condition= "+taglist.getCondition().get(j));
k++;
texts[k].setText("Low= "+taglist.getLow().get(j));
k++;
texts[k].setText("High= "+taglist.getHigh().get(j));
k++;
texts[k].setText("Icon= "+taglist.getIcon().get(j));
k++;
j++;
if(j>=5){
j=0;
}
}
/** Set the layout view to display */
setContentView(MyScrollView);
}
}
我向SO提出的问题是,谁会帮助我获得各个城市的平坦Xml档案? 我几乎在所有城市都拥有URL,而且我可以认为,通过在我法典中提到的URL(例如天气.php?city=auckland)的末尾改变城市名称。 我从《名单》开始,我有大约20-30个城市作为名单上的党派储存在《意见》中。 每当我点击特定地点时,我就希望获得该特定城市的平坦XMl档案。
请就此向我提供指导。
增 编
EDITED:
xml contents:
<?xml version="1.0" encoding="UTF-8"?>
<weather>
<current_conditions>
<current>ಹೊಗೆಯಾವೃತ</current>
<temp>95</temp>
<humidity>Humidity: ೨೩%</humidity>
<wind_condition>Wind: ಪೂ at 13 km/h</wind_condition>
<icon>smoke.gif</icon>
</current_conditions>
<forecast_information>
<forecast0>
<day>ಶನಿ.</day>
<condition>ಬಹುಪಾಲು ಬಿಸಿಲು</condition>
<low>25</low>
<high>36</high>
<icon>mostly_sunny.gif</icon>
</forecast0>
<forecast1>
<day>ರ.</day>
<condition>ಶುಭ್ರ</condition>
<low>25</low>
<high>35</high>
<icon>sunny.gif</icon>
</forecast1>
<forecast2>
<day>ಸೋ.</day>
<condition>ಬಹುಪಾಲು ಬಿಸಿಲು</condition>
<low>25</low>
<high>36</high>
<icon>mostly_sunny.gif</icon>
</forecast2>
<forecast3>
<day>ಮಂ.</day>
<condition>ಬಹುಪಾಲು ಬಿಸಿಲು</condition>
<low>26</low>
<high>33</high>
<icon>mostly_sunny.gif</icon>
</forecast3>
</forecast_information>