Let’s examine in more detail the interfaces in Figure 16.1.
As you saw in Figure 16.1, many DOM nodes implement the Node interface. They might also have other properties and methods in addition to those that the Node interface provides.
These DOM interfaces are said to extend the Node interface. Figure 16.2 shows the interfaces in DOM Level 2 Core that extend the Node interface.
In general, the names of the node types that inherit from the Node interface can be readily understood from their names. The DocumentType interface, for example, corresponds to the DOCTYPE declaration.
DOM interfaces can be extended several levels deep. Figure 16.3 shows the node types that extend the CharacterData interface.
Both the Comment and Text interfaces extend the CharacterData interface. The Text interface itself is extended by the CDATASection interface. You will look at these text-oriented interfaces later, but first let’s look briefly at the properties and methods of the Node interface.
The Node interface has the following properties:
The Node interface has the following methods:
The child nodes of the Document node implement the NodeList interface.
The NodeList interface has the length property, which is a read-only property of type Number. The NodeList interface has the item(index) method, which returns a Node object.
You can locate the attributes of an element using the NamedNodeMap interface.
The NamedNodeMap interface has the length property, a read-only property of type Number.
The NamedNodeMap interface has the following methods, all of which return a Node object:
Before looking in more detail at the interfaces in Figure 16.1, you will look briefly at generally relevant interfaces.
The DOMImplementation interface has no properties, but it does provide methods that allow a programmer to determine what is supported by that implementation.
The hasFeature(feature , version ) method returns a Boolean value enabling you to test the availability of particular features. The createDocument(namespaceURI , qualifiedName , doctype ) method enables you to create a new XML document. The createDocumentType(qualifiedName , publicId , systemId ) method enables you to create a new DOCTYPE declaration.
Several programming languages use a concept called an exception to handle errors that occur while a program is running. The DOM provides a DOMException interface. An exception is often said to be thrown and is caught by an exception handler.
The DOMException interface has a single code property, which is of type number. The value of the code property corresponds to the type of exception that has been raised. When programming, you should consider the likely types of errors that might occur and provide error-handling code that provides appropriate responses to those problems.