Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Stax Parser

Posted on 2004-11-01
3
Medium Priority
?
1,702 Views
Last Modified: 2013-11-23
Hello Guys,

Have you heard abt STAX parser

http://www.google.co.in/search?hl=en&q=%22stax+parser%22++java&btnG=Search&meta=

If any body have used this parser, please share your experiences.

If possible some examples are appreciated.

Thanks
Sudhakar
0
Comment
Question by:sudhakar_koundinya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 3

Expert Comment

by:vikraman_b
ID: 12470376
HI..
i too aware of it..
check this link..
it will be helpful
http://www.sys-con.com/story/?storyid=45083&DE=1
0
 
LVL 3

Accepted Solution

by:
vikraman_b earned 1000 total points
ID: 12470383
In the above link u can check this code......

Listing 1: Reading with the XMLStreamReader

        while(sr.hasNext()){
            sr.next();
            if(sr.getEventType() == XMLStreamConstants.START_ELEMENT){
                if(sr.getLocalName().equals("sometext") &&
      sr.getNamespaceURI().equals("http://www.example.com/foons")){
                    // get all the text content of <sometext> and store in
                              someText
                              variable
                    someText = sr.getElementText();
                } else if(sr.getLocalName().equals("bar")
                       &&
   sr.getNamespaceURI().equals("http://www.example.com/barns")){
                    // get the value of the ratio attribute
                    ratio = sr.getAttributeValue(null,"ratio");
                }
            } else {
                // ignore event
            }
        }


Listing 2: Reading with the XMLEventReader

        while(er.hasNext()){
            XMLEvent event = er.nextEvent();
            if(event.getEventType() == XMLStreamConstants.START_ELEMENT){
                StartElement se = event.asStartElement();
                if(se.getName().equals(new
                        QName("http://www.example.com/foons","sometext"))){
                    someText = se.getElementText();
                } else if(se.getName().equals(new
                         QName("http://www.example.com/barns","bar"))){
                    Attribute ratioAttr = se.getAttributeByName(new
                              QName("ratio"));
                    if(ratioAttr != null){
                        ratio = ratioAttr.getValue();
                    }
                }
            } else {
                // ignore event
            }
        }


Listing 3: Writing with the XMLStreamWriter

XMLOutputFactory factory = XMLOutputFactory.newInstance();
        factory.setProperty("javax.xml.stream.isPrefixDefaulting",

Boolean.TRUE);
       
         XMLStreamWriter sw = factory.createXMLStreamWriter(new
         FileOutputStream(destination),"UTF-8");
        sw.writeStartDocument();
        sw.writeStartElement("http://www.example.com/foons", "foo");
        sw.writeStartElement("http://www.example.com/foons", "sometext");
        sw.writeCharacters(someText);
        sw.writeEndElement();
        sw.writeStartElement("http:/www.example.com/barns", "bar");
        sw.writeAttribute("ratio",ratio);
        sw.writeEndElement();
        sw.writeEndElement();
        sw.writeEndDocument();
        sw.close();


Listing 4: Writing with the XMLEventWriter

        XMLOutputFactory factory = XMLOutputFactory.newInstance();
        XMLEventFactory eventFac = XMLEventFactory.newInstance();
        factory.setProperty("javax.xml.stream.isPrefixDefaulting",Boolean.TRUE);
        XMLEventWriter ew =  factory.createXMLEventWriter(new
            FileOutputStream(destination),"UTF-8");
        ew.add(eventFac.createStartDocument());
        ew.add(eventFac.createStartElement(null,"http://www.example.com/foons",
            "foo"));
        ew.add(eventFac.createStartElement(null,"http://www.example.com/foons",
            "sometext"));
        ew.add(eventFac.createCharacters(someText));
        ew.add(eventFac.createEndElement(null,"http://www.example.com/foons",
            "sometext"));
        ew.add(eventFac.createStartElement(null,"http:/www.example.com/barns",
            "bar"));
        ew.add(eventFac.createAttribute("ratio",ratio));
        ew.add(eventFac.createEndElement(null,"http://www.example.com/barns",
            "bar"));
        ew.add(eventFac.createEndElement(null,"http://www.example.com/foons",
            "foo"));
        ew.add(eventFac.createEndDocument());
        ew.close();
0
 
LVL 14

Author Comment

by:sudhakar_koundinya
ID: 12470390
Friend,

I have seen that link. See above I have already given google's link for this

I want your experience in using STAX. In other words how it is efficient when compared with DOM/SAX

How can we handle XSLT with stax and so on

thanks
Sudhakar
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question