| Author |
XML parsing through saxparser in java
|
Mohd Shariq
Greenhorn
Joined: Feb 04, 2011
Posts: 3
|
|
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
Joined: Oct 25, 2008
Posts: 2700
|
|
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:
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Rob Spoor
Sheriff
Joined: Oct 27, 2005
Posts: 19216
|
|
|
Moving to our XML forum.
|
SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
|
 |
g tsuji
Ranch Hand
Joined: Jan 18, 2011
Posts: 359
|
|
[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.
|
 |
 |
|
|
subject: XML parsing through saxparser in java
|
|
|