Java DOM Parser: A Comprehensive Guide with Examples - Quiz
Total: 5 questions
1. Describe the work of the DOM parser.
Describe the work of the DOM parser.
DOM creates an object-oriented model of an XML document. All elements are represented as objects organized into a hierarchical tree structure which corresponds to the hierarchy of the processed XML document. DOM gives a possibility to navigate the tree structure, change elements and attributes, and create new XML documents in memory.
2. Disadvantages of DOM parsers.
Disadvantages of DOM parsers.
They are slow compared to SAX, and consumes a lot of memory.
3. Which classes are used to create a DOM parser?
Which classes are used to create a DOM parser?
javax.xml.parsers. DocumentBuilderFactory and javax.xml.parsers. DocumentBuilder.
4. Example of creating a DOM tree from an XML document stored in a file.
Example of creating a DOM tree from an XML document stored in a file.
String file = ...
FileInputStream fileStream = new FileInputStream(file);
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder parser = factory.newDocumentBuilder();
Document xmlDoc = parser.parse(fileStream);
5. Common supertype of all DOM elements.
Common supertype of all DOM elements.
Node interface.
Page 1 of 1