0

here i want to get parse Map values in one array list or hash-map i dnt know which is the better way.

Here is my XMl file

I am using SAX parser to parse this thing

<Navigation useNavi="1" auto="1" diable="0" >
<Map MapName="paris" MapPath="\Storage Card\PA\xyz" LoadAtStartup="1" />
<Map MapName="swiss" MapPath="\Storage Card\SW\abc" LoadAtStartup="0" />
<Map MapName="delhi" MapPath="\Storage Card\DE\del" LoadAtStartup="1" />
</Navigation>

Here i want to pasre Map tag , i cant do it easily and also get its attributes values but i want to know how can i manage this Map element attributes values for a example MapName is paris and i want to use its respective values in future like LoadAtStartup attribute value.

How can i manage these 3 maps values ?

Thanks

Sam

sam_k
  • 5,983
  • 14
  • 76
  • 110

2 Answers2

0

Create a class:

class MapObject
    public string MapName;
    public string MapPath;
    public boolean LoadAtStartup;

    public MapObject(string name, string path, boolean loadAtStartup){
       this.MapName = name;
       this.MapPath = path;
       this.LoadAtStartup = loadAtStartup;
    }

And a container for the class instances:

List<MapObject> mapsObjects = new List<MapObject>();

And new instances in your JSON parser (pseudo code, you already have this)

 for each object in JSON data{
     mapObjects.add(new MapObject(name attribute, path attribute, loadAtStartup attribute);
 }
Simon
  • 14,407
  • 8
  • 46
  • 61
0

There are different solutions for your question. Maybe the following will give you a possible solution:

    HashMap<String, Pair<String, Boolean>> mapEntries = new HashMap<String, Pair<String,Boolean>>();

    //Inside SAX callback
    String place = attrs.getValue("MapName");
    String path = attrs.getValue("MapPath");
    Boolean isLoadAtStartup = Integer.parseInt(attrs.getValue("LoadAtStartup")) == 1;
    mapEntries.put(place, new Pair<String, Boolean>(path, isLoadAtStartup));

The above uses the android.util.Pair class. You can use your user-defined container class (as illustrated by @Simon) as well.

Rajesh
  • 15,724
  • 7
  • 46
  • 95