• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

SAX Help

 
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have a XML like this.


With SAX I can able to find whether a given <id> exist or not,
like this,
public void startElement(String nsURI, String localName,
String qName, Attributes attrs)
throws SAXException{
if ( localName.equals("LocationCoded") ) codestatus = true;
}
public void characters(char[] ch, int start, int length)
throws SAXException {
if (codestatus){
String value = new String(ch, start, length);
if (value.equals("ADALV")) {
System.out.println("Found!.");
}
}
}
I'm fine with this.
Now my problem is
Printing the <service> value for a given valid <id>
That is if <id> TP5 is given then it should print "hello world".
if <id> UT5 is given then it should print "javaranch"
With DOM i can able to do this,but my xml file size is 3.46MB so i want to use SAX.
Please give me some coding tips on how to do this with SAX.
Regards
Bala
 
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Balaji,
I feel that there will not be any straight-forward SAX solution for the problem you put here. The only possible way out i see here is come out with an algorithm and implement it. I'm sure you are aware of this Please donot get angry with me
Have a good day.
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
 
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you can count on the fact that the service element always follows the id element you can do the following -
Create two instance variables -

In the startElement method please place (raw is the third parameter) -

In the characters method please add -

That should do it.
Cheers,
Dan
 
Jayadev Pulaparty
Ranch Hand
Posts: 662
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dan's suggestion sounds good for me.
BTW, these face icons are really funny I like them a lot
 
Balaji Loganathan
author and deputy
Posts: 3150
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Dan Drillich:


Dan, you gave me a beautiful solution.Shit me, i'm not even thinking about this logic.But tried something different than this.
Thanks a lot Dan,its worked perfectly.
Hi jaya,
this is for you
:roll:
Have a nice day.
 
Dan Drillich
Ranch Hand
Posts: 1183
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Balaji,
You are welcome!
Dan
 
I've never won anything before. Not even a tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic