Torna indietro   Hardware Upgrade Forum > Software > Programmazione

Deep Tech Revolution: così Area Science Park apre i laboratori alle startup
Deep Tech Revolution: così Area Science Park apre i laboratori alle startup
Siamo tornati nel parco tecnologico di Trieste per il kick-off del programma che mette a disposizione di cinque startup le infrastrutture di ricerca, dal sincrotrone Elettra ai laboratori di genomica e HPC. Roberto Pillon racconta il modello e la visione
HP OMEN MAX 16 con RTX 5080: potenza da desktop replacement a prezzo competitivo
HP OMEN MAX 16 con RTX 5080: potenza da desktop replacement a prezzo competitivo
HP OMEN MAX 16-ak0001nl combina RTX 5080 Laptop e Ryzen AI 9 HX 375 in un desktop replacement potente e ben raffreddato, con display 240 Hz e dotazione completa. Autonomia limitata e calibrazione non perfetta frenano l'entusiasmo, ma a 2.609 euro è tra le proposte più interessanti della categoria.
Recensione Google Pixel 10a, si migliora poco ma è sempre un'ottima scelta
Recensione Google Pixel 10a, si migliora poco ma è sempre un'ottima scelta
Google ha appena rinnovato la sua celebre serie A con il Pixel 10a, lo smartphone della serie più conveniente se consideriamo il rapporto tra costo e prestazioni. Con il chip Tensor G4, un design raffinato soprattutto sul retro e l'integrazione profonda di Gemini, il colosso di Mountain View promette un'esperienza premium a un prezzo accessibile. E il retro non ha nessuno scalino
Tutti gli articoli Tutte le news

Vai al Forum
Rispondi
 
Strumenti
Old 16-01-2012, 10:49   #1
darkmax
Senior Member
 
L'Avatar di darkmax
 
Iscritto dal: Nov 2001
Città: Torino
Messaggi: 3092
[Android] Importare coordinate da un documento

Buongiorno a tutti,
sto creando un'applicazione in android e ho la necessità di importare delle coordinate da un file xml su web per disegnare pinpoint su una mappa google.

Ho alcune domande:

1) il file è nella forma:

Codice:
<td:traffic_data xmlns:td="http://www.prova.it" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.prova.it/traffic_data 
http://www.prova.it" generation_time="2012-01-16T10:41:33+01:00" start_time="2012-01-16T10:36:33+01:00" end_time="2012-01-16T10:41:33+01:00" source="prova.IT">
<td:location_reference>
<td:tmc_info tabcd="1" cid="25"/>
</td:location_reference>
<td:PK_data Name="Prova1" ID="1" status="1" Total="134" Free="83" tendence="-1" lat="45.07243" lng="7.67480"/>
<td:PK_data Name="Prova2" ID="46" status="1" Total="305" Free="1" tendence="-1" lat="45.03660" lng="7.67249"/>
<td:PK_data Name="Prova3" ID="2" status="1" Total="434" lat="45.06355" lng="7.68357"/>
<td:PK_data Name="Prova4" ID="3" status="1" Total="858" lat="45.07248" lng="7.66716"/>
</td:traffic_data>
2) Ho la necessità di importare Name, Total e Free.. Ho visto questo esempio:

Codice:
package test.example;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.URL;

import javax.xml.parsers.SAXParser;
import javax.xml.parsers.SAXParserFactory;

import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
import org.xml.sax.XMLReader;
import org.xml.sax.helpers.DefaultHandler;

import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.widget.TextView;

public class XMLParsingDemo extends Activity {

    private final String MY_DEBUG_TAG = "Prova coordinate";

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle icicle) {
        super.onCreate(icicle);

        /* Create a new TextView to display the parsingresult later. */
        TextView tv = new TextView(this);

        try {
            /* Create a URL we want to load some xml-data from. */

        DefaultHttpClient hc = new DefaultHttpClient();  
        ResponseHandler <String> res = new BasicResponseHandler();  
        HttpPost postMethod = new HttpPost("http://www.prova.it/example.xml");
        String response=hc.execute(postMethod,res); 

        /* Get a SAXParser from the SAXPArserFactory. */
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();

        /* Get the XMLReader of the SAXParser we created. */
        XMLReader xr = sp.getXMLReader();
        /* Create a new ContentHandler and apply it to the XML-Reader*/ 
        ExampleHandler myExampleHandler = new ExampleHandler();
        xr.setContentHandler(myExampleHandler);

        /* Parse the xml-data from our URL. */
        InputSource inputSource = new InputSource();
        inputSource.setEncoding("UTF-8");
        inputSource.setCharacterStream(new StringReader(response));

        /* Parse the xml-data from our URL. */
        xr.parse(inputSource);
        /* Parsing has finished. */

        /* Our ExampleHandler now provides the parsed data to us. */
        ParsedExampleDataSet parsedExampleDataSet = myExampleHandler.getParsedData();


        /* Set the result to be displayed in our GUI. */
        tv.setText(response + "\n\n\n***************************************" + parsedExampleDataSet.toString());



        } catch (Exception e) {
            /* Display any Error to the GUI. */
            tv.setText("Error: " + e.getMessage());
            Log.e(MY_DEBUG_TAG, "WeatherQueryError", e);
        }
        /* Display the TextView. */
        this.setContentView(tv);
    }

    public class ExampleHandler extends DefaultHandler {

        // ===========================================================
        // Fields
        // ===========================================================

        private boolean traffic_data = false;
        private boolean location_reference = false;
        private boolean PK_data = false;

        private ParsedExampleDataSet myParsedExampleDataSet = new ParsedExampleDataSet();

        // ===========================================================
        // Getter & Setter
        // ===========================================================

        public ParsedExampleDataSet getParsedData() {
            return this.myParsedExampleDataSet;
        }

        // ===========================================================
        // Methods
        // ===========================================================
        @Override
        public void startDocument() throws SAXException {
            this.myParsedExampleDataSet = new ParsedExampleDataSet();
        }

        @Override
        public void endDocument() throws SAXException {
            // Nothing to do
        }

        /** Gets be called on opening tags like: 
         * <tag> 
         * Can provide attribute(s), when xml was like:
         * <tag attribute="attributeValue">*/
        @Override
        public void startElement(String uri, String localName, String qName, org.xml.sax.Attributes atts) throws SAXException {
            super.startElement(uri, localName, qName, atts);
            if (localName.equals("outertag")) {
                this.in_outertag = true;
            }
            else if (localName.equals("innertag")) {
                String attrValue = atts.getValue("sampleattribute");
                myParsedExampleDataSet.setExtractedString(attrValue);
                this.in_innertag = true;
            }
            else if (localName.equals("mytag")) {
                this.in_mytag = true;
            }
            else if (localName.equals("tagwithnumber")) {
                // Extract an Attribute
                String attrValue = atts.getValue("thenumber");
                int i = Integer.parseInt(attrValue);
                myParsedExampleDataSet.setExtractedInt(i);
            }

        }


        /** Gets be called on closing tags like: 
         * </tag> */
        @Override
        public void endElement(String namespaceURI, String localName, String qName)
                throws SAXException {
            if (localName.equals("outertag")) {
                this.in_outertag = false;
            }else if (localName.equals("innertag")) {
                this.in_innertag = false;
            }else if (localName.equals("mytag")) {
                this.in_mytag = false;
            }else if (localName.equals("tagwithnumber")) {
                // Nothing to do here
            }
        }       


        /** Gets be called on the following structure: 
         * <tag>characters</tag> */
        @Override
        public void characters(char ch[], int start, int length) {
            if(this.in_mytag){
                myParsedExampleDataSet.setExtractedString(new String(ch));
            }
        }
    }

    public class ParsedExampleDataSet {
        private String extractedString = null;
        private int extractedInt = 0;

        public String getExtractedString() {
            return extractedString;
        }
        public void setExtractedString(String extractedString) {
            this.extractedString = extractedString;
        }

        public int getExtractedInt() {
            return extractedInt;
        }
        public void setExtractedInt(int extractedInt) {
            this.extractedInt = extractedInt;
        }

        public String toString(){
            return "\n\n\nExtractedString = " + this.extractedString
                    + "\n\n\nExtractedInt = " + this.extractedInt;
        }

    }

}
Non so come faccio ad estrarre quei valori.. Mi potete aiutare?

3) Essendo più di una la coordinata.. Come la implemento nel codice? Cioè.. Io avrò una lista e disegnerò uno per uno i pinpoint? Che dite?

Vi ringrazio
__________________
Agenzia di comunicazione Torino
darkmax è offline   Rispondi citando il messaggio o parte di esso
Old 16-01-2012, 21:16   #2
darkmax
Senior Member
 
L'Avatar di darkmax
 
Iscritto dal: Nov 2001
Città: Torino
Messaggi: 3092
up
__________________
Agenzia di comunicazione Torino
darkmax è offline   Rispondi citando il messaggio o parte di esso
Old 17-01-2012, 14:57   #3
darkmax
Senior Member
 
L'Avatar di darkmax
 
Iscritto dal: Nov 2001
Città: Torino
Messaggi: 3092
up
__________________
Agenzia di comunicazione Torino
darkmax è offline   Rispondi citando il messaggio o parte di esso
 Rispondi


Deep Tech Revolution: così Area Science Park apre i laboratori alle startup Deep Tech Revolution: così Area Science P...
HP OMEN MAX 16 con RTX 5080: potenza da desktop replacement a prezzo competitivo HP OMEN MAX 16 con RTX 5080: potenza da desktop ...
Recensione Google Pixel 10a, si migliora poco ma è sempre un'ottima scelta Recensione Google Pixel 10a, si migliora poco ma...
6G, da rete che trasporta dati a rete intelligente: Qualcomm accelera al MWC 2026 6G, da rete che trasporta dati a rete intelligen...
CHUWI CoreBook Air alla prova: design premium, buona autonomia e qualche compromesso CHUWI CoreBook Air alla prova: design premium, b...
Il nuovo MacBook Neo ha una memoria SSD ...
Xbox Project Helix, le prime specifiche ...
Annunci pubblicitari sulla TV quando cam...
Prezzi aumentati del 50% durante la nott...
Sconti studiati per singolo utente: Sony...
Addio alla Kia Niro EV, il crossover sar...
Apple crede nel suo iPhone Fold: la prod...
Fortnite, un nuovo listino per i pacchet...
Ecco i nuovi Sonos Play ed Era 100 SL: d...
Razer svela il futuro del gaming potenzi...
Tre robot Narwal in offerta: pulizia aut...
Gracenote denuncia OpenAI: ChatGPT addes...
Microsoft AI Tour Milano: dall'efficienz...
Asus ExpertBook Ultra: Intel Core Ultra ...
Intel presenta i processori desktop Core...
Chromium
GPU-Z
OCCT
LibreOffice Portable
Opera One Portable
Opera One 106
CCleaner Portable
CCleaner Standard
Cpu-Z
Driver NVIDIA GeForce 546.65 WHQL
SmartFTP
Trillian
Google Chrome Portable
Google Chrome 120
VirtualBox
Tutti gli articoli Tutte le news Tutti i download

Strumenti

Regole
Non Puoi aprire nuove discussioni
Non Puoi rispondere ai messaggi
Non Puoi allegare file
Non Puoi modificare i tuoi messaggi

Il codice vB è On
Le Faccine sono On
Il codice [IMG] è On
Il codice HTML è Off
Vai al Forum


Tutti gli orari sono GMT +1. Ora sono le: 00:45.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2026, Jelsoft Enterprises Ltd.
Served by www3v