IT Community - Software Programming, Web Development and Technical Support

What is STAX?

This is a discussion on What is STAX? within the XML and SOAP forums, part of the Web Development category; Hi guys, can any once expalin What is STAX? Thanks devarajan.V...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > XML and SOAP

Register FAQ Members List Calendar Mark Forums Read
  #1  
Old 07-25-2007, 06:24 AM
devarajan.v devarajan.v is offline
D-Web Master
 
Join Date: May 2007
Posts: 382
devarajan.v is on a distinguished road
Question What is STAX?

Hi guys,

can any once expalin What is STAX?


Thanks
devarajan.V
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2  
Old 07-26-2007, 04:39 AM
vadivelanvaidyanathan vadivelanvaidyanathan is offline
D-Web Genius
 
Join Date: Feb 2007
Posts: 801
vadivelanvaidyanathan is on a distinguished road
Default Re: What is STAX?

StAX is the Streaming API for XML defined by JSR 173.
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3  
Old 08-11-2007, 02:17 AM
Venkat Venkat is offline
D-Web Master
 
Join Date: Mar 2007
Posts: 347
Venkat is on a distinguished road
Thumbs up Re: What is STAX?

hey,

The Streaming API for XML (StAX), a streaming Java-based, event-driven, pull-parsing API for reading and writing XML documents. StAX enables you to create bidrectional XML parsers that are fast, relatively easy to program, and have a light memory footprint.

StAX provides is the latest API in the JAXP family, and provides an alternative to SAX, DOM, TrAX, and DOM for developers looking to do high-performance stream filtering, processing, and modification, particularly with low memory and limited extensibility requirements.
__________________
Venkat
knowledge is Power
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4  
Old 10-13-2007, 01:35 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 905
S.Vinothkumar is on a distinguished road
Smile Re: What is STAX?

It would be streaming in the sense that it would be very lazy and not read things in until needed. It would also be streaming in the sense that it would read everything forwards (but not backwards).

Here's what code that used such an API would look like.

Code:
URL url = ...
XMLStream xml = XXXFactory(url.inputStream()) ;


// process each <book> element in this document.
// the <book> element may have subnodes.
// You get a DOM/JDOM like tree rooted at the next <book>.


while (xml.hasContent()) {
XMLElement book = xml.getNextElement("book");
processBook(book);
}
Another variation would be:
Note that the implementation of the container would be lazy. I.e. it would only read things as they are pulled by the container.

Code:
Collection<XMLElement> books = xml.getAllElement("book");
for (XMLElement book : books) {
processBook(book);
}
There would also be XPath aware versions of the above.

Code:
Collection<XMLElement> books = xml.getAllElement("/*/libraries[city='chicago']/book");
for (XMLElement book : books) {
processBook(book);
}

And methods for controlling the depth of the produced tree. Something like (not sure of the best syntax).

This example would create a collection of books, but only retain the name, ISBN and author of each and ignore everything else.


Code:
Collection<XMLElement> books = xml.getAllElement("/*/libraries[city='chicago']/book",
restrict("name|ISBN|author"));
for (XMLElement book : books) {
processBook(book);
}
Such a system could be very memory efficient and easy to program with. It is what I thought Stax would be, before I saw the Stax examples.
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5  
Old 10-13-2007, 01:48 AM
S.Vinothkumar S.Vinothkumar is offline
D-Web Genius
 
Join Date: May 2007
Posts: 905
S.Vinothkumar is on a distinguished road
Smile Re: What is STAX?

Reading Documents with StAX

XMLStreamReader is the key interface in StAX. This interface represents a cursor that's moved across an XML document from beginning to end. At any given time, this cursor points at one thing: a text node, a start-tag, a comment, the beginning of the document, etc. The cursor always moves forward, never backward, and normally only moves one item at a time. You invoke methods such as getName and getText on the XMLStreamReader to retrieve information about the item the cursor is currently positioned at.

A typical StAX program begins by using the XMLInputFactory class to load an implementation dependent instance of XMLStreamReader:

Code:
URL u = new URL("http://www.cafeconleche.org/");
InputStream in = u.openStream();
XMLInputFactory factory = XMLInputFactory.newInstance();
XMLStreamReader parser = factory.createXMLStreamReader(in);
__________________
S.VinothkumaR
Behind me is infinite power,
Before me is Endless Possibility,
Around me is Boundless Opportunity,
Why should I fear!
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #6  
Old 04-22-2008, 09:42 PM
GDevakii GDevakii is offline
D-Web Sr.Programmer
 
Join Date: Aug 2007
Posts: 125
GDevakii is on a distinguished road
Smile Re: What is STAX?

Streaming API for XML (StAX)
The Streaming API for XML (StAX) is a groundbreaking new Java API for parsing and writing XML easily and efficiently. Spearheaded by BEA, StAX has passed the final approval ballot of the Java Community Process (see JSR-173).

Processing XML is a standard task in most computing environments. Until now, developers have typically used two approaches: the Simple API for XML processing (SAX) and the Document Object Model (DOM). Although both methods have their advantages, both also have significant disadvantages, such as a lack of iterative processing (SAX) and a potential performance loss resulting from reading the entire XML document into memory (DOM).

StAX solves these problems by providing more control of XML parsing to the programmer, in particular by exposing a simple iterator-based API and an underlying stream of events. Methods such as next() and hasNext() allow an application developer to ask for the next event, or pull the event, rather than handle the event in a callback. StAX also enables the programmer to stop processing the document at any time, skip ahead to sections of the document, and get subsections of the document.

StAX helps you process XML faster and easier in these typical use cases:

* Data binding, a two-way process that reads and writes XML (unmarshaling and marshaling) to and from a programming language data structure
* SOAP message processing (SOAP is an XML message transport format used predominantly by Web services)
* Parsing a specific XML vocabulary
* Processing pipelined XML
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


All times are GMT -7. The time now is 04:15 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.
Our Partners
One Way Moving Companies | Stamford Dentist | Euro Millions Lottery | Home Loans| Furniture

SEO by vBSEO 3.0.0