• 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

XML parsing through saxparser in java

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator




hi I am new to java xml pasing . I am using saxparser for parsing this above xml file.

I want to fetch


I am not able to fetch abstract properly I want all the data in one string i.e Objectiv ,Result conclusion and method in one string.

This is my java code for doing this




I am not getting the correct result. I am new to java please help me to short out this problem.
I will be very thankful.
sample code will be very helpful
Sorry for my bed english
thanks in advance
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I've added some code tags to your post making it much easier to read. Please do so yourself next time. You can read about them here.

I would do something like:
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Moving to our XML forum.
 
Ranch Hand
Posts: 734
7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
[0] First of all, the xml document seems mal-formed (maybe due to some artifact in posting?). This is an example.
><Title>Tropical medicine & international health : TM & IH</Title>
The ampersands are not escaped... There are a couple of instances like this. This must be rectified before doing anything else.

[1] Then the main functionality of DefaultHandler pose problem, as far as I can see (as it is not easy reading, in particular there involves some user-defined type Abstract...).

[1.1] Your DefaultHandler is written as (local) anonymous inner class. This is very hard to debug in particular when it involves many lines of codes. It would be fine if it is fairly short or its functionality is very plain and easy to track. This is not the case. Hence, I would say put the whole subclassing of DefaultHandler into a separate class, an inner class if need be and inner to StringToXML class.

[1.2] And then, there seems to be a big problem in the scope and visibility of objAbstract. It is declared in the outer class. But, the code seems tasking to make change to it inside the anonymous inner class. That poses problem. (If I recall the error be asking the reference need be declared final in the first place and that's put the situation into a dilemma...)

[1.3] If still keeping in the same scheme, an objAbstract need to be declared inside the (extension of) DefaultHander. Also the setting should then be fine within the DefaultHandler. The problem is to retrieve it in the outer class. This can be done by reflection, adding obscurity to the approach. Something like this (recall that objAbstract would be declared within the handler)

[2] I would say, repeating [1.1], it would gain more clarity and less obscurity if you separate the subclass of DefaultHandler into a named inner class to StringToXML. Declare the objAbstract inside the handler. Then, the return statement would then be as simple as this with much clarity.
 
What's that smell? I think this tiny ad may have stepped in something.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic