SAX or DOM?

You just saw two examples of transformations, one with the SAX and the other with the DOM. Which one should you use? The answer, like all other things in life, is it depends!

As you saw in earlier chapters, SAX is a serial processing parser and does not create an in-memory representation of the XML data. So, the information about the element is lost as soon as the parser reaches the next element. Although this makes it fast and light on resources, there is no way to determine where exactly you are in the document hierarchy, or the relationship between the elements.

In contrast, DOM creates an in-memory representation of the XML data. Although this feature makes it possible for an application to randomly access and modify the XML data ...

Get Java™ APIs for XML Kick Start now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.