DOM Flashcards
1
Q
What is DOM and why is it used?
A
DOM is the Document Object Model. This can be used with a Java API.
It reads the xml file in can be used to create or amend xml documents.
The API provides:
- Interfaces and objects to represent and manipulate a document
- Semantics of them.
- Relationships amongst interfaces and objects
2
Q
What are the important methods for amending an XML document?
- Not including the methods for creating a new document.*
- Clue: there are 8!*
A
- .getDocumentElement - return a list of child objects of any node.
- .getChildNodes - return a list of child objects of any node
- .parse - reads the file in (xml errors picked up) and returns a datatype
- .getElementsByTagName(String tagname) - returns NodeList representing the result of an in-order traversal of the doc in which Nodes with elements of tag name
- .createXXXX - create new Nodes e.g. createTextNode
- .item(i) - get Node in list of position i
- .replaceChild(newNode, oldNode) - replaces the oldNode with newNode.
- .getNodeValue() - return value of the node
3
Q
What are the important methods for creating an XML document?
A
- .newDocument() - replaces parse
- .createElement(“name”) - create element before append
- .appendChild(new) - append child to new document or Node
4
Q
How do you copy part of an XML document to another one?
A
By using import
5
Q
What risks/differences are there between using DOM and creating your own code to manipulate XML in Java?
A
Your own code may be missing something and you can’t confirm it is generating well formed XML correctly. Whereas we know DOM will always generate and parse XML correctly.