Java API for XML Processing (JAXP) - Quiz

Total: 15 questions

1. 

What is JAXP?

Java API for XML-Processing is for processing XML data with applications written in the Java programming language.

2. 

Types of XML parsers.

- SAX (Simple API for XML)

- DOM (Document Object Model)

3. Differences between StAX and SAX APIs.
- StAX-enabled clients are easier to code than SAX clients. - StAX is a bidirectional API: it can read and write XML documents. SAX is read only, so another API is needed to write XML documents. - SAX is a push API, and StAX is pull.
4. Main API sets of the StAX API.
A cursor API and an iterator API.
5. Describe Cursor API of StAX.
The StAX cursor API gives a possibility to walk through an XML document from beginning to end. The cursor can point to one thing at a time, and always moves forward, never backward, usually one infoset element at a time.
6. Interfaces of Cursor API of StAX.
XMLStreamReader and XMLStreamWriter.
7. Main methods of XMLStreamReader interface.
int next() throws XMLStreamException; boolean hasNext() throws XMLStreamException; String getText(); String getLocalName(); String getNamespaceURI();
8. Main methods of XMLStreamWriter interface.
void writeStartElement(String localName) throws XMLStreamException; void writeEndElement() throws XMLStreamException; void writeCharacters(String text) throws XMLStreamException;
9. Describe Iterator API of StAX.
The StAX iterator API represents an XML document stream as a set of discrete event objects. These events are pulled by the application and provided by the parser in the order in which they are read in the source XML document.
10. The iterator interfaces of StAX.
The base iterator interface is XMLEvent, and there are subinterfaces for each event type. The primary parser interface for reading iterator events is XMLEventReader, and the primary interface for writing iterator events is XMLEventWriter.
11. Methods of XMLEventReader interface.
XMLEvent nextEvent() throws XMLStreamException; boolean hasNext(); XMLEvent peek() throws XMLStreamException;
12. Methods of XMLEventWriter interface.
void flush() throws XMLStreamException; void close() throws XMLStreamException; void add(XMLEvent e) throws XMLStreamException; void add(Attribute attribute) throws XMLStreamException;
13. Benefits of StAX iterator API.
- Objects created from the XMLEvent subclasses are immutable, and can be used in arrays, lists, and maps, can be passed through the applications even after the parser has moved on to subsequent events. - It is possible to create subtypes of XMLEvent that are either completely new information items or extensions of existing items but with additional methods. - It is possible to add and remove events from an XML event stream in much simpler ways than with the cursor API.
14. In which cases cursor API is more preferable than iterator API?
- In case of programming for a particularly memory-constrained environment, like Java ME, it is possible to create smaller, more efficient code with the cursor API. - When performance is highest priority.
15. In which cases iterator API is more preferable than cursor API?
- For creation of XML processing pipelines. - To change the event stream. - If the application should be able to handle pluggable processing of the event stream. - In general using the iterator API is recommended because it is more flexible and extensible.
Page 1 of 1