Witam mam mały problem z parsowaniem pliku xml:
http://dl.dropbox.com/u/15624346/szukaj.xml
Polega on na tym, że wczytuje się do programu tylko pierwszy znacznik <aws:location ... > a ja chciałbym aby wczytało wszystkie znaczniki.
Poniżej mój kod który parsuje plik
URL url;
try
{
ProgressDialog dialog = ProgressDialog.show(MainActivity.this, "","Please wait for few seconds...", true);
url = new URL("http://dl.dropbox.com/u/15624346/szukaj.xml"]http://dl.dropbox.com/u/15624346/szukaj.xml);
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
DocumentBuilder db = dbf.newDocumentBuilder();
Document doc = db.parse(new InputSource(url.openStream()));
doc.getDocumentElement().normalize();
NodeList szukajnode = doc.getElementsByTagName("aws:locations");
String wynik[];
String code[];
String country[];
wynik = new String[szukajnode.getLength()];
code = new String[szukajnode.getLength()];
country = new String[szukajnode.getLength()];
for (int i = 0; i < szukajnode.getLength(); i++)
{
Node node = szukajnode.item(i);
Element fstElmnt = (Element) node;
NodeList nameList = fstElmnt.getElementsByTagName("aws:location");
Element nameElement = (Element) nameList.item(0);
nameList = nameElement.getChildNodes();
wynik[i] = nameElement.getAttribute("cityname");
code[i] = nameElement.getAttribute("citycode");
country[i] = nameElement.getAttribute("countryname");
Log.v("miasto", wynik[i]);
Log.v("citycode", code[i]);
Log.v("kraj", country[i]);
Log.v("len",String.valueOf(szukajnode.getLength()));
dialog.dismiss();
}
}
catch (Exception e)
{
Toast.makeText(getApplicationContext(),"Błąd pobierania listy wyników szukania",Toast.LENGTH_LONG).show();
e.printStackTrace();
}