Questions tagged [stax]

StAX stands for Streaming API for XML. It's a streaming Java-based, event-driven, pull-parsing API for reading and writing XML documents.

Traditionally, XML APIs are either:

  • tree based (like DOM) - the entire XML content is read and assembled into an in-memory, hierarchical object graph.
  • event based (like SAX) - the application registers to receive events as entities are encountered within the source document.

Both have advantages: tree based parsers allow random access to the document while the latter requires a smaller memory footprint and is usually faster. StAX sits between these two methodologies, because the application "pulls" the data from the XML data stream at its convenience. The application (not the parser) controls how to fetch data from xml. It was introduced in JSR-173 in March 2004 and it's a new feature in JDK 6.0.

StAX implementations have a reader and a writer APIs. Both with two levels: "raw" cursor access and object-based "event" access.

The "raw" cursor access classes included in JDK are:

The "event" based classes included in JDK are:

Other implementations are:

A performance comparison with a few basic sample snippets can be found here.

648 questions
172
votes
16 answers

"Content is not allowed in prolog" when parsing perfectly valid XML on GAE

I've been beating my head against this absolutely infuriating bug for the last 48 hours, so I thought I'd finally throw in the towel and try asking here before I throw my laptop out the window. I'm trying to parse the response XML from a call I made…
Adrian Petrescu
  • 16,629
  • 6
  • 56
  • 82
86
votes
6 answers

When should I choose SAX over StAX?

Streaming xml-parsers like SAX and StAX are faster and more memory efficient than parsers building a tree-structure like DOM-parsers. SAX is a push parser, meaning that it's an instance of the observer pattern (also called listener pattern). SAX was…
Rinke
  • 6,095
  • 4
  • 38
  • 55
42
votes
4 answers

What is 'Push Approach' and 'Pull Approach' to parsing?

Under the push parsing approach, a push parser generates synchronous events as a document is parsed, and these events can be processed by an application using a callback handler model This is the text given in the book Pro XML Development with…
An SO User
  • 24,612
  • 35
  • 133
  • 221
26
votes
10 answers

StAX XML formatting in Java

Is it possible using StAX (specifically woodstox) to format the output xml with newlines and tabs, i.e. in the form: someData instead of: someData If…
Lehane
  • 47,588
  • 14
  • 53
  • 53
20
votes
2 answers

integrating org.apache.poi and the javax.xml.stream.* package (stax-api) in android - how to set the --core-library argument in Android Studio?

I'm using Android studio 1.5.1 I'd like to include the org.apache.poi-ooxml library in my android project. To include that library I needed to include some other library dependencies, among which the stax-api library. The problem with stax api is…
SlumpA
  • 882
  • 12
  • 24
20
votes
2 answers

which .jar file has javax.xml.stream.*?

I have problems again with my Mac running Java 1.5.... where do I get a .jar file that has javax.xml.stream.XMLInputFactory ? I want to use StAX but don't know how to get it set up right. I can't seem to get this setup. I've now downloaded…
Jason S
  • 184,598
  • 164
  • 608
  • 970
18
votes
3 answers

stax xml validation

I know I can validate xml-file when I use sax. But can I validate when I use Stax?
Tim
  • 440
  • 1
  • 5
  • 12
18
votes
4 answers

Best StAX Implementation

My quick search reveals the reference implementation (http://stax.codehaus.org), the Woodstox implementation (http://woodstox.codehaus.org), and Sun's SJSXP implementation (https://sjsxp.dev.java.net/). Please comment on the relative merits of…
Jeff C
  • 445
  • 4
  • 10
15
votes
6 answers

CXFServlet throws java.lang.NoSuchMethodError: org.codehaus.stax2.ri.EmptyIterator.getInstance()Lorg/codehaus/stax2/ri/EmptyIterator;

I'm using Java 11, Spring Boot 2.1.1 and Apache CXF 3.2.7 to expose a SOAP web service that imports an XSD schema. In the WSDL it shows like:
JuanMoreno
  • 2,498
  • 1
  • 25
  • 34
14
votes
3 answers

What is the difference between XMLStreamReader and XMLEventReader?

I surf through the web. I found that the XMLStreamReader is Cursor style API for parsing XML. And XMLEventReader is Iterator style API for Parsing XML.Could any one tell me in detail?
Arunselvan
  • 163
  • 1
  • 1
  • 8
13
votes
4 answers

Iterating over a two level structure using nested iterators

I have the following two level XML structure. A list of boxes, each containing a list of drawers. ...
Roland
  • 7,525
  • 13
  • 61
  • 124
13
votes
5 answers

how to override a service provider in java

This is more a general question by example: I'm using xstream and woodstox, woodstox comes with a service provider for javax.xml.stream.XMLOutputFactory in woodstox jar registering com.ctc.wstx.stax.WstxOutputFactory. I want to provide my own…
Shalom938
  • 909
  • 2
  • 10
  • 24
12
votes
3 answers

Reading a big XML file using stax and dom

I need to read several big (200Mb-500Mb) XML files, so I want to use StaX. My system has two modules - one to read the file ( with StaX ); another module ( 'parser' module ) suppose to get a single entry of that XML and parse it using DOM. My XML…
Noam
  • 3,049
  • 10
  • 34
  • 52
12
votes
2 answers

Do I need stax-api-1.0.x in my web app when using JDK 1.6?

I am currently developing a web app that uses Jersey for REST. I use maven, and both stax-api-1.0.1 and 1.0.2 are pulled into my web-inf/lib. I thought the stax api were a aprt of JDK1.6? Why are those JARS included in my web application? Here is my…
Glenn Bech
  • 6,103
  • 4
  • 39
  • 56
12
votes
7 answers

Reading Huge XML File using StAX and XPath

The input file contains thousands of transactions in XML format which is around 10GB of size. The requirement is to pick each transaction XML based on the user input and send it to processing system. The sample content of the file
Siva Arunachalam
  • 7,582
  • 15
  • 79
  • 132
1
2 3
43 44