Like this article? We recommend
Cursor vs. Iterator APIs
As a developer, if you decide you want to use StAX pull parsing, you need to choose between the cursor and iterator APIs. In making your selection, it should be noted that the iterator API includes some additional capabilities not supported by the cursor API:
- Instances of XMLEvent subclasses are immutable, and can be freely used in arrays, maps, and lists without concern for concurrent modification.
- Subtypes of XMLEvent can be defined with totally new information items or can extend existing items with additional methods.
In deciding on which API to use, follow these general guidelines:
- For memory-constrained environments such as J2ME, use the more efficient cursor API.
- When high performance is key, such as when constructing low-level libraries or utility infrastructure, the cursor API is leaner and meaner.
- XML processing pipelines work well with the iterator API.
- If you need to modify the event stream, use the iterator API.
- If there are no strong drivers for selecting one or the other, choose the iterator API. It’s more flexible and will be easier to adapt as your application evolves.