Particular Tag Parsing

by Sasikumar.S » Mon, 01 Feb 2010 11:31:22 GMT


Sponsored Links
 Hi,

How to parse only the particular tag using SAX Parser?..

*sample.xml*
*
*
<main type="">
<sub>
<conname>George</conname>
<conphonenumber>840123456</conphonenumber>
<extra>US</extra>
</sub>
</main>

when i try to parse the above sample.xml i'm getting all the values(conname,
canphonenumber & extra).
But i need only conname & conphonenumber

-- 
Thanks & Regards
Sasikumar.S

--



Particular Tag Parsing

by Kumar Bibek » Mon, 01 Feb 2010 12:46:43 GMT


 SAX parsing is done line by line, so there is no way that you can pick
up a specific tag if you are SAX parsing.

Kumar Bibek




--


Sponsored Links


Particular Tag Parsing

by Sasikumar.S » Mon, 01 Feb 2010 12:52:14 GMT


 Ok. Thank u very much for ur reply.

In SAX Parser it will parse line by line.
How can we get only the particular data alone.

Ex:-

In a XML file there are 5 tags. SAX is parsing all the 5 tags.
I need only the 1,3 & 4 tag value.
How to retrieve that?.
I did not need 2 & 5th value.

can you pls give some idea for this?..





>



Particular Tag Parsing

by Kumar Bibek » Mon, 01 Feb 2010 12:56:50 GMT


 If you want to have a look at a code sample, please find an example
here.

 http://www.xmlpull.org/v1/doc/api/org/xmlpull/v1/XmlPullParser.html 

You just need to ignore the data which you do not need.






> >



Particular Tag Parsing

by Frank Weiss » Mon, 01 Feb 2010 12:59:46 GMT


 SAXParser does NOT parse line by line. That's incorrect. What you need is
something like this:

 @Override
 public void characters(char[] ch, int offset, int count) {
  sb.append(ch, offset, count);
 }
@Override
 public void endElement(String namespaceUri, String localName, String qName)
{
  if (localName.equals("title"))
   title = sb.toString();

--



Particular Tag Parsing

by Sasikumar.S » Mon, 01 Feb 2010 13:13:15 GMT


 Thank u frank.




>



Particular Tag Parsing

by Kumar Bibek » Mon, 01 Feb 2010 13:49:05 GMT


 Well, true, it's not line by line, to be more specific, it's character
by character.

What I meant was, you can't just pick up specific data from the XML,
you will have to go through the whole XML, or till the tag which you
want to fetch.

Kumar Bibek.




> >



Particular Tag Parsing

by Sasikumar.S » Mon, 01 Feb 2010 13:54:31 GMT


 Ok Thank U Kumar






> > >



Particular Tag Parsing

by Sasikumar.S » Mon, 01 Feb 2010 18:27:48 GMT


 Thank U for responding previous Questions.

One more thing Guys.

Now i'm getting one more doubt in that.

I need to parse the below XML file:

<item>
<2>2item</2>
<3>3item</3>
<1>1item</1>
<4>4item</4>
</item>

In that i'm fetching data from <1>, <2>,<3> & <4>.
But i'm getting value as <2>, <3>, <1> & <4> in order wise.

How to get in my wish order?.

Please give some idea guy?..





>



Particular Tag Parsing

by Kevin Duffey » Mon, 01 Feb 2010 23:58:58 GMT


 You will have to sort your data once you get it. You can't control the order
it's processed. If you know for a fact that it will only be 4 items, you
could create an array of size 4, then stick the data in the specific index
spot of the array. Or you can add it to a list then sort it.  That is an odd
XML tho. I've not seen xml return something like that...are you responsible
for the XML being returned, or have no control over it?





>>



Particular Tag Parsing

by hari » Tue, 02 Feb 2010 12:33:26 GMT


 hi Sasikumar.S do you know how to update xml file using Sax parser.

--



Particular Tag Parsing

by Sasikumar.S » Tue, 02 Feb 2010 12:35:10 GMT


 I don't know Hari.





>



Particular Tag Parsing

by Kevin Duffey » Tue, 02 Feb 2010 13:10:33 GMT


 Hari, as far as I know you'd usually parse the document into an object, do
any updating of the object, then write it back out overwriting the previous
version. SAX doesn't store the xml in memory, it streams it, like xmlpull
does and you assemble an object tree from the xml as your needs require. You
don't have to assmble an object tree that is identical to the xml as well.
This is probably part of the reason DOM is so slow and requires as much as
8x the XML size in memory to store. Frankly, I'd go with xmlpull. It's
vastly easier to work with and generally as fast if not faster than sax.






>>



Particular Tag Parsing

by Sasikumar.S » Tue, 02 Feb 2010 13:16:15 GMT


 Hi Kevin,

Which is more faster and easier to use?.

I need to Parse a XML. That file contains more than 12000 lines.

First i tried to use DOM but it is very slow. It is taking more than 10
minutes tom parse.
Now i'm trying to use SAX.
Which one is very fast whether SAX or XMLPull Parser ?..






>>>



Particular Tag Parsing

by Sasikumar.S » Tue, 02 Feb 2010 17:36:42 GMT


 How to parse the tag by my order.

Ex:-

<sample>

<iphone>nice</iphone>
<Android>super</Android >
< ipad >excellent</ipad>

</sample>

In this XML file i need to get order as,

<android>, <iphone> & <ipad>.

But i'm getting as

<iphone> , <android> & <ipad>.

How to get like <android>, <iphone> & <ipad>.







>>>>



Other Threads

1. Newbie Nexian Journey

Pagi all..
Perkenalkan nama saya Ocky.
Baru beli Nexian Journey, Sabtu kemaren di ICS. Newbie mohon petunjuknya di 
dunia Android. Kek na menarik juga. Boleh tanya sbb?

1. Dimana tempat baca2 newbie Android?
2. Apakah Nexian Journey bisa di upgrade ke Froyo? 
3. Apakah bisa upgrade Android sendiri? Tak perlu dibawa ke CS?

-€hank You€ 


Sent from my AXIS Worry Free BlackBerry smartphone

-- 
"Indonesian Android Community [id-android]" 

2. app2sd liquid?

para suhu,
mau tanya utk Liqiud apa ada app2sd yang cocok ? gimana caranya yah?
Maklum noobie nih..

-- 
"Indonesian Android Community [id-android]" 

3. Showing Google MyMaps

4. nanya e-book reader di android

5. OOT..Just for fun..

6. Edit ReTweet di twitter

7. Twitter / Facebook source code