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
-3
votes
1 answer

Why I get NullPointerException when running StAX Parser?

I'm trying to write a StAX XML Parser in Java, but always get NullPointerException error. Please help me to solve this issue. Full problem: Exception in thread "main" java.lang.NullPointerException …
Silentpig
  • 1
  • 4
-3
votes
1 answer

How to parse an Xml which contains the field with an new line using java parsers

How to parse an Xml which contains the field with an new line as it is using java parsers. https://nithesh/testing dfsgndfisfgsdgsdgsfggsfgsdfgs rfk/ffsgsdgfdssg32afaaaaffasa …
Nithesh
  • 31
  • 8
-5
votes
1 answer

How do I parse this XML File in Java

I have the following file in xml and I need to Parse it in Java. The file has more than 200 rows, I just gave two rows as sample. Please help with best method to parse large files ie DOM, SAX, StaX and a working example to prase this file would be…
1 2 3
43
44