0

I have searched and watched numerous youtube videos on parsing XML for Android, but I still find it hard to understand. Reason being that none really focus on the problem I have.

I have this calculator to calculate prices on a given service. The calculator uses several int variables but I want to get the value for these variables from a XML file hosted on my Dropbox (this is only for private use).

The code and tutorial I find usually either focus on setting the value from the XML file to GUI or just getting value from a local stored XML file. Does anyone have a good and easy to understand code/info on how to just access the value from the XML file and store it in variables?

My XML looks like this :

    <timepris>200</timepris>

    <marsipanlite>100</marsipanlite>
    <marsipanmiddels>150</marsipanmiddels>
    <marsipanmye>200>200</marsipanmye>

    <sjokoladebunn>200</sjokoladebunn>
    <sukkerbunn>150</sukkerbunn>

My code for summarize is :

        private void regneUtSum() {

            int kakeBunnTotal = antallKakerBunner * kakebunnpris;
            int timerTotal = antallTimer * timepris;
            int totalSum = kakeBunnTotal + timerTotal + marsipanpris;
            String totalSumText = String.valueOf(totalSum);
            sum.setText(totalSumText);

        }
Praise
  • 557
  • 2
  • 8
  • 23
  • If you know how to get value from a local stored XML file - download the file and do it on the local file. – zapl Nov 05 '13 at 18:29
  • I need it to be stored on the web. :) And I don´t know how to get the value from a local store XML file either. :) – Praise Nov 05 '13 at 18:30
  • You can't access it while it is on the web. So you have to download it to your device in some way to get the data. Either you do it in two steps and retrieve the file from the web into a file, then parse the file or you do it in one step and parse it directly from some `InputStream` (which you also do when you parse it from a file) - like http://stackoverflow.com/questions/8846295/read-the-remote-xml-file-in-android – zapl Nov 05 '13 at 18:32
  • You can parse directly from URL, can´t you? Like Yahoo Webservices etc? – Praise Nov 05 '13 at 18:35
  • Yes you can, but it's actually very similar to writing it to a temporary file first. You still download the data but you feed it directly into the parser instead of into a file and from there into the parser. It might be a tad quicker not to use a file. – zapl Nov 05 '13 at 18:36
  • That is what I want to do. Feed it directly in to the parser and store it as values in the variables. But it all seems a little confusing for me when I try to read up on it and when I watch tutorials. – Praise Nov 05 '13 at 18:38

0 Answers0