parsing XML online file Android

modernmobile

New Member
I am making an application for Android and I need to display an XML file of this page:http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=7009I tried the solutions given on the page but I find it wrong since it is not displayed when you run the application. I just want to show "tipo= DOLAR SPOT INTERCAMBIO"This is the XML CODE
QNpRJ.png
and this is my code:xmlpruebaprueba.jar\[code\]XMLdataCollected sitesList= null;@Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_xmlpruebaprueba); //creando un Layout LinearLayout layout = new LinearLayout(this); layout.setOrientation(1); //creando TextView TextView Registro[]; TextView Tipo[]; try { SAXParserFactory spf = SAXParserFactory.newInstance(); SAXParser sp = spf.newSAXParser(); XMLReader xr = sp.getXMLReader(); URL sourceURL = new URL("http://www.bovalpo.com/cgi-local/xml_bcv.pl?URL=7009"); handlingXml HandlingXml = new handlingXml(); xr.setContentHandler(HandlingXml); xr.parse(new InputSource(sourceURL.openStream())); }catch (Exception e){ System.out.println("XML Parsing Exception= " + e); } sitesList = handlingXml.sitesList; Registro = new TextView[sitesList.getRegistro().size()]; Tipo = new TextView[sitesList.getTipo().size()]; for (int i = 0; i < sitesList.getRegistro().size(); i++) { Registro = new TextView(this); Registro.setText("Registro = "+sitesList.getRegistro().get(i)); Tipo = new TextView(this); Tipo.setText("Tipo = "+sitesList.getTipo().get(i)); layout.addView(Registro); layout.addView(Tipo); } } \[/code\]}and this is my handler\[code\]Boolean currentElement = false;String currentValue = http://stackoverflow.com/questions/11547768/null;public static XMLdataCollected sitesList = null;public static XMLdataCollected getDataCollected (){ return sitesList;}public static void setSitesList(XMLdataCollected sitesList){ handlingXml.sitesList = sitesList;}@Overridepublic void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { // TODO Auto-generated method stub currentElement = true; if(localName.equals("Root")) { sitesList = new XMLdataCollected(); }else if (localName.equals("Registro")){ String attr = attributes.getValue("tipo"); sitesList.setTipo(attr); }}@Overridepublic void endElement(String uri, String localName, String qName) throws SAXException { // TODO Auto-generated method stub currentElement = false; if (localName.equalsIgnoreCase("Registro")) sitesList.setRegistro(currentValue); else if (localName.equalsIgnoreCase("Root")) sitesList.setRoot(currentValue); }@Overridepublic void characters(char[] ch, int start, int length) throws SAXException { // TODO Auto-generated method stub if (currentElement) { currentValue = http://stackoverflow.com/questions/11547768/new String(ch, start, length); currentElement = false; }}}\[/code\]and this is my dataCollectedpublic class XMLdataCollected {\[code\]private ArrayList<String> root = new ArrayList<String>();private ArrayList<String> registro = new ArrayList<String>();private ArrayList<String> tipo = new ArrayList<String>();public ArrayList<String> getRoot (){ return root;}public void setRoot(String root){ this.root.add(root);}public ArrayList<String> getRegistro (){ return registro;}public void setRegistro(String registro){ this.registro.add(registro);}public ArrayList<String> getTipo (){ return tipo; }public void setTipo(String tipo){ this.tipo.add(tipo);}\[/code\]}
 
Back
Top