2. DocumentElement: provides access to root element References an Element Node In XHTML will refer to <html> element CreateElement(tagName): Create a new element node with given tag name Creating an element doesn’t add it to document, must be appended: oDoc.documentElement.appendChild(oDoc.createElement(“Tests”)) Document InterfaceCommon Members Note:“oDoc” is a document object 9/29/2009
3. CreateTextNode(value): Create a text node using the argument as the specified value oElement = oDoc.createElement(“DueDate”) oElement.appendChild(oDoc.createTextNode(“10/5/2009”) oDoc.documentElement.appendChild(oElement) Creates an element node with the text node having specific date Document InterfaceCommon Members – 2 9/29/2009
4. CreateAttribute(attributeName): Create an attribute with specified name oAttrib = oDoc.CreateAttribute(“Sequence”) oAttrib.Value = “2” Create attribute Sequence with value = 2 GetElementsByTagName(tagName): Returns all elements with specified name as a NodeList (similar to an array or collection) varProjectNodes = oDoc.getElementsByTagName(“Project”) Get all project nodes Document InterfaceCommon Members - 3 9/29/2009
5. Properties Attributes Parent Node Child Nodes First Child Last Child Previous Sibling Next Sibling Node Name Node Type Methods HasChildNodes() AppendChild() CloneNode() InsertBefore() RemoveChild() ReplaceChild() Node InterfaceCommon Members 9/29/2009
6. Attributes returns a namedNodeMap that contains all attributes of an Element node oDoc.getElementsByTagName(“Assignment”)[0].Attributes Get Attributes of first assignment element ParentNode provides access to node that “owns” current node oDoc.getElementsByTagName(“Assignment”)[0].parentNode Get parent of first Assignment element ChildNodes returns children of current node oDoc.getElementsByTagName(“Project”)[0].childNodes Returns list of nodes found in first projects node Node Interface Examples 9/29/2009