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
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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
  1. .getDocumentElement - return a list of child objects of any node.
  2. .getChildNodes - return a list of child objects of any node
  3. .parse - reads the file in (xml errors picked up) and returns a datatype
  4. .getElementsByTagName(String tagname) - returns NodeList representing the result of an in-order traversal of the doc in which Nodes with elements of tag name
  5. .createXXXX - create new Nodes e.g. createTextNode
  6. .item(i) - get Node in list of position i
  7. .replaceChild(newNode, oldNode) - replaces the oldNode with newNode.
  8. .getNodeValue() - return value of the node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the important methods for creating an XML document?

A
  1. .newDocument() - replaces parse
  2. .createElement(“name”) - create element before append
  3. .appendChild(new) - append child to new document or Node
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

How do you copy part of an XML document to another one?

A

By using import

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly