Android setvalidating xmlpullparserfactory v1 xmlpull org
However, in my opinion XMLPULL is not yet suitable as a general purpose Java API for processing XML.
It should not be your first choice for most applications.
The trade-offs made in the name of size may be acceptable if you're working in J2ME.
They are completely unacceptable in a desktop or server environment.
The namespace flaw can be fixed by setting the appropriate feature, and in theory the internal DTD subset problem can be as well. Furthermore, the defaults are exactly backwards from what they should be for both; and while there might rarely be justification for turning off namespace processing, turning off processing of the internal DTD subset is simply not allowed by the XML specification.
A parser that does not read the internal DTD subset is not an XML parser.
This is probably only worthwhile when the DOM equivalent program would use too much memory.
However, it is best to test and verify your expectations about data formats. Pull parsers don't yet support validation, but XMLPULL offers an alternative.
If you expect a particular token to be present in the document, you can require it using a type and an optional name and namespace.
However, as the name indicates, it is based on a pull model rather than a push model. This simple example doesn't demonstrate the full power of the XMLPULL API.
In XMLPULL the client is in control rather than the parser. Since the client application controls the process, it's easy to write separate methods for different elements.
The object problems are less fundamentally wrong but still extremely troubling. The prevalence of switch statements and stacks of if-else-if blocks just to test the return type of the method is a classic symptom of failure to take advantage of polymorphism.