DOM Interfaces Properties and Methods

Because of space constraints, this section looks at the properties and methods of selected interfaces only.

The Document Interface

The Document interface represents an XML document. The Document interface has the following properties:

  • doctype— Read-only, of type DocumentType

  • implementation— Read-only, of type DOMImplementation

  • documentElement— Of type Element

The methods of the Document interface can be used to create new parts of an XML document or to retrieve information about the document. The Document interface has the following methods:

  • createAttribute(name)— Returns an Attr object

  • createAttributeNS(namespaceURI, qualifiedName)— Returns an Attr object

  • createCDATASection(data)— Returns a CDATASection object

  • createComment(data)— Returns a Comment object

  • createDocumentFragment()— Returns a DocumentFragment object

  • createElement(tagName)— Returns an Element object

  • createElementNS(namespaceURI, qualifiedName)— Returns an Element object

  • createEntityReference(name)— Returns an EntityReference object

  • createProcessingInstruction(target,data)— Returns a ProcessingInstruction object

  • createTextNode(data)— Returns a Text object

  • getElementsByTagName(tagname)— Returns a NodeList object

  • getElementsByTagNameNS(namespaceURI, localName)— Returns a NodeList object

  • importNode(importedNode, deep)— Returns a Node object

The DocumentType Interface

The DocumentType interface is the DOM representation of the DOCTYPE declaration.

The DocumentType interface has the following properties:

  • entities— Read-only, of type NamedNodeMap

  • internalSubset— Read-only, of type String

  • name— Read-only, of type String

  • notations— Read-only, of type NamedNodeMap

  • publicId— Read-only, of type String

  • systemIdRead-only, of type String

The Element Interface

The Element interface represents an element in an XML document.

The Element interface has the tagName property, which is a read-only property of type String.

The Element interface has the following methods:

  • getAttribute(name)— Returns a value of type String

  • getAttributeNS(namespaceURI, localName)— Returns a value of type String

  • getAttributeNode(name)— Returns a value of type Attr

  • getAttributeNodeNS(namespaceURI, localName)— Returns a value of type Attr

  • getElementsByTagName(tagname)— Returns a NodeList object

  • getElementsByTagNameNS(namespaceURI,localName)— Returns a NodeList object

  • hasAttribute(name)— Returns a value of type Boolean

  • hasAttributeNS(namespaceURI, localName)— Returns a value of type Boolean

  • removeAttribute(name)— Returns no value

  • removeAttributeNode(oldAttr)— Returns a value of type Attr

  • removeAttributeNS(namespaceURI, localName)— Returns no value

  • setAttribute(name,value)— Returns no value

  • setAttributeNode(newAttr)— Returns a value of type Attr

  • setAttributeNodeNS(newAttr)— Returns a value of type Attr

  • setAttributeNS(namespaceURI, localName)— Returns no value

The Attr Interface

The Attr interface is the DOM representation of an attribute in an XML document.

The Attr interface has the following properties:

  • name— Read-only, of type String

  • ownerElement— Read-only, of type Element

  • specified— Read-only, of type Boolean

  • value— Of type String

The Attr interface has no methods specific to it.

The CharacterData Interface

The CharacterData interface is intended to contain character data. The Comment and Text interfaces extend the CharacterData interface.

The CharacterData interface has the following properties:

  • data— Of type String

  • length— Read-only, of type Number

The CharacterData interface has the following methods:

  • appendData(arg)— Has no return value

  • deleteData(offset, count)— Has no return value

  • insertData(offset, arg)— Has no return value

  • replaceData(offset, count, arg)— Has no return value

  • substringData(offset, count)— Returns a value of type String

The Text Interface

The Text interface has no properties specific to it.

The Text interface has the splitText(offset ) method, which returns a Text object.

In Chapter 17 you will create some examples using DOM properties and methods.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset