XML Code is
<?xml version="1.0" encoding="UTF-8" ?>
<opml version="1">
<head>
<title>Radio</title>
<status>200</status>
</head>
<body>
<outline type="link" text="Local" URL="http://..............." key="local" />
<outline type="link" text="Music" URL="http://.............." key="music" />
<outline type="link" text="walk" URL="http://...................." key="walk" />
<outline type="link" text="Sports" URL="http://..........." key="sports" />
<outline type="link" text="Place" URL="http://..............." key="Place" />
<outline type="link" text="Verbal" URL="http://............." key="Verbal" />
<outline type="link" text="Podcasts" URL="http://....................." key="podcast" />
</body>
</opml>
This is Generic xml parser
go to the link http://androidosbeginning.blogspot.com/2010/09/generic-xml-parsing-in-android.html
hope this will solve the issue you are facing.
SAX: Simple xml parsing. It parses node by node Traversing is from top to bottom Low memory usage Back navigation is not possible with sax.
I wouldn't save them in a vector necessarily only if you really have to for a special purpose. I'd save them in a
HashMap
instead so you can reference them by their keys instead.I need to see your XML structure to help you with an in depth answer.
EDIT: Here is your answer. Late but still.
Given your XML structure looks like this.
To get all the data you need parsed into a useful
HashMap
the Handler could look like this.The HashMap
outlineMap
will hold all your outline entries and the HashMapoutlineData
will hold the attributes in every single outline tag. The Stringkey
is defined because we need it to get the keys and set them correctly for every outlineData.As you can see outlineMap is always declared in the
startDocument()
method this way we ensure that every time your parse using this handler you will have an empty new HashMap.In the
startElement()
method we check if the qualified name of the tag equals toOUTLINE
while ignoring the case of it. If this tag occurs we declare a new HashMap so we can hold each attribute set of every outline tag. Then we assign a value to our key string by parsing the key value of the attribute key of the outline tag. Then we pass every other interesting attribute to ouroutlineData
HashMap using theput()
method. This method accepts only a string as a key and a string as a value by our definition.Now we move on to our
endElement()
method which also checks for the occurrence ofOUTLINE
again ignoring the case. If it occurs we set the content of your first outlineMap entry by setting the key string from earlier as the key and the outlineData HashMap as the value. Here our HashMap accepts a string as its key and an object as its value (it accepts virtually everything as its value as everything in Java is an object in fact).And now you have your ready to use HashMap filled with the parsed data.
In my example I pass our final HashMap outlineMap to a setter in another class in the endDocument() method. That means when the parsing is done.
Here is a short explanation how the SAX parser uses this methods so you have a better clue of whats happening.
Of course there are several other methods available but for you this methods are the more interesting ones right now. The characters method might not be that interesting for your actual needs tho.
I hope it helps. If you need to know more just ask by comment.