Archive

Archive for January, 2010

StAX(Streaming API for XML) and Other parsers

January 17, 2010 Leave a comment

To handle xml in java, there are mainly two API were used, DOM and SAX. But now StAX API is also part of java parsing API. Here I am writing some of the differences I found while learnig parsers for writing PojoXML open source project.

StAX
The main goal of StAX API(http://jcp.org/en/jsr/detail?id=173) is to give “parsing control to the programmer” by providing a simple iterator based API. This allows the programmer to ask for the next event (pull the event) ,because of this property StAX is called as pull parser .StAX was created to address limitations in the two most prevalent parsing APIs, SAX and DOM.

DOM vs SAX vs StAX
DOM creates a fully tree based structure of xml document in the memory and traverse randomly. DOM takes lots of memory. So its inefficient for processing large xml document.

But SAX parser is more efficient in terms of memory usage. SAX is a streaming API it parse sequentially when an xml Infoset found it fires events. SAX doesn’t provide random access to xml data. We don’t have control over the xml parsing. When an event(element or attribute or text or CDATA founds) occurs SAX parser send data to your program(Push Parsing).

In case of StAX (Pull Parsing) API we have to call parser API to get next element when we wanted. You can control the parsing from your code. Using Pull parser we can filter xml document, means we can ignore the unnecessary elements. Pull parsing library is smaller than push parser.

When there is memory limitation you should go for streaming API for example cell phone application.
Woodstox is a StAX implementation.
Which parser you are using? And How you handles xml parsing in your application

Categories: Uncategorized Tags:

something about TDD

January 3, 2010 Leave a comment

What is Test Driven Development?
This is question asked by one of my friend. Here i am writing my answer for that. Test Driven Development means writing Test Cases first and then developing code. This is best way to achieve a test suit. Its time consuming process, but in my open source project and my personal recomendation is to follow Test Driven Development. There are lots of reason i have found for that from the opensource project i have written and i am writing now.

i). Any time you can change the internal structure of the project without changing the functionality. Your test cases makes sure that your chages is right or wrong.

ii). Writing test cases will makes you to break down the code according to functionality. and ensures that that part is tested succesfully

iii). If a new person, who knows the project partially can add/change the code[no need to worry about wether its effect to other part of project]

iv). Doing TDD we can tell exact persentage of project status.

Some disadvantages are:

i). its boring task, not a creative work

ii) time consuming while following a faster schedule.

iii). Developer must have a good understanding on the automated testing API[JUnit or TestNG,..]

This all are my understandings that i got from books and my experiance.
please reply your comments on this

Categories: Uncategorized
Follow

Get every new post delivered to your Inbox.