Next freebie in 28 Hours*
Consider, for example, a corporate aerospace giant that has a hierarchical employee structure: nodes represent employees, and connecting tree edges (lines) indicate immediate supervisor and subordinates.
A DOM Interface provides an API that can be invoked by the user's program, and it is used to recursively traverse the XML document tree. It has certain standard, flexible API methods such as:
firstSibling(,) lastSibling(,) nextSibling(,) parent(,) firstChild(,) lastChild(,) and nextChild() among others. We shall now see how these APIs can be used to navigate the XML document. As is apparent, this is a very general API: the programmer doesn't need to know beforehand the number of elements, nested elements, etc. in the XML document.
Consider in particular the node representing the employee whose title is "VP Research & Development." In this node context, the above-mentioned API would return the following results, by traversing the tree in downward or upward direction, depending on the requirement:
firstSibling(): "VP Operations"
lastSibling(): "VP Business & Management"
nextSibling(): "VP Business & Management"
parent(): "President & CEO"
firstChild(): "PE Research & technology"
lastChild(): "PE Deployment"
nextChild(): (Depends on context)
To illustrate these results, note that the DOM internally maintains a pointer or marker to determine which node of the XML DOM tree is the current one. All the above operations return values relative to the current position of the pointer.
The DOM model is an old model found in early literature describing the invention of XML and related standards. Modern day XML-parsing standards have moved ahead, but we are learning about the DOM since there is a very large code-base out there in terms of XML language libraries and client code. DOM, in its heyday, had a huge following and is still the most general API around.
Have a question but don't want to ask it publicly? If you are a prime member just ask right here and we will get back to you within 48 hours. Not prime yet? no worries you can ask publicly below.