This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes XML and Related Technologies and the fly likes XML parsing  through saxparser in java Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Engineering » XML and Related Technologies
Bookmark "XML parsing  through saxparser in java" Watch "XML parsing  through saxparser in java" New topic
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: 19541
    
  16

Moving to our XML forum.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
g tsuji
Ranch Hand

Joined: Jan 18, 2011
Posts: 464
    
    2
[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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: XML parsing through saxparser in java
 
Similar Threads
Crazy date program
DateRec
Missing return statement
Returning A List Of Variables From A Folder Of Documents And Returning Them Into A New Document
Want to convert my code in method