This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

XML parsing through saxparser in java

 
Mohd Shariq
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
Wouter Oet
Saloon Keeper
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • 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:
 
Rob Spoor
Sheriff
Pie
Posts: 20665
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Moving to our XML forum.
 
g tsuji
Ranch Hand
Posts: 669
3
  • Mark post as helpful
  • send pies
  • 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.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic