This page contains the XML for <SCRIPT> DOMAttr object documentation.
Return to W3C DOM Parser Documentation Main Page
NOTE: DOMAttr descends from
DOMNode and inherits
all of the properties and methods of the DOMNode object
-
CONTENTS
-
DOMAttr - object description
-
-
-
Native Methods:
-
DOMAttr - getName method
-
DOMAttr - getSpecified method
-
DOMAttr - getOwnerElement method
-
DOMAttr - getValue method
-
DOMAttr - setValue method
-
-
-
Inherited Methods:
-
DOMNode - getNodeName method
-
DOMNode - getNodeValue method
-
DOMNode - setNodeValue method
-
DOMNode - getNodeType method
-
DOMNode - getParentNode method
-
DOMNode - getChildNodes method
-
DOMNode - getFirstChild method
-
DOMNode - getLastChild method
-
DOMNode - getPreviousSibling method
-
DOMNode - getNextSibling method
-
DOMNode - getAttributes method
-
DOMNode - getNamespaceURI method
-
DOMNode - getPrefix method
-
DOMNode - getLocalName method
-
DOMNode - getOwnerDocument method
-
DOMNode - insertBefore method
-
DOMNode - replaceChild method
-
DOMNode - removeChild method
-
DOMNode - appendChild method
-
DOMNode - hasChildNodes method
-
DOMNode - cloneNode method
-
DOMNode - getElementsByTagName method
-
DOMNode - getElementsByTagNameNS method
-
DOMNode - setPrefix method
-
DOMNode - normalize method
-
DOMNode - isSupported method
-
DOMNode - getXML method
-
DOMNode - hasAttributes method
DOMAttr - object description
The DOMAttr interface represents an attribute in an DOMElement object.
DOMAttr objects inherit the DOMNode interface, but since they are not
actually child nodes of the element they describe, the DOM does not
consider them part of the document tree. Thus, the DOMNode methods
getParentNode, getPreviousSibling, and getNextSibling return a null
value for DOMAttr objects. The DOM takes the view that attributes
are properties of elements rather than having a separate identity
from the elements they are associated with. Furthermore, DOMAttr
nodes may not be immediate children of a DOMDocumentFragment.
However, they can be associated with DOMElement nodes contained within
a DOMDocumentFragment. In short, users and implementors of the
DOM need to be aware that DOMAttr nodes have some things in common with other
objects inheriting the DOMNode interface, but they also are quite distinct.
DOMAttr - getName method
W3C DOM Level 1
DOMAttr.getName()
accepts:
N/A
returns:
String - the name of the attribute
throws:
N/A
The getName method returns the name of the queried DOMAttr object.
Example:
function xmljsDOMExample() {
var xml;
xml = ""
+ "<?xml version=\"1.0\"?>"
+ "<ROOTNODE>"
+ "<TAG1 foo=\"goo\" id=\"tag1_id\" />"
+ "</ROOTNODE>";
//instantiate the W3C DOM Parser
var parser = new DOMImplementation();
//load the XML into the parser and get the DOMDocument
var domDoc = parser.loadXML(xml);
//get the root node
var docRoot = domDoc.getDocumentElement();
//find tag1 by searching by its id
var tag1 = domDoc.getElementById("tag1_id");
//get a DOMNamedNodeMap of the attributes for tag1
var namedNodeMap = tag1.getAttributes();
//get the DOMAttr node with the name of "foo"
var fooNode = namedNodeMap.getNamedItem("foo");
//the following should be "foo"
alert(fooNode.getName());
}// end function xmljsDOMExample
DOMAttr - getSpecified method
W3C DOM Level 1
DOMAttr.getSpecified()
accepts:
N/A
returns:
boolean - XML for <SCRIPT> always returns true
throws:
N/A
The getSpecified method returns an indication of whether or not this attribute was
explicitly given a value in the original XML document or whether the attribute's value
was obtained via the XML document's DTD. The getSpecified method returns true if the
attribute's value was specified in the XML document and false otherwise.
NOTE: XML for <SCRIPT> is a non-validating parser
and thus does not support attributes obtaining their values from DTDs. Therefor, the
getSpecified method will always return true when called
from within XML for <SCRIPT>.
Example:
function xmljsDOMExample() {
var xml;
xml = ""
+ "<?xml version=\"1.0\"?>"
+ "<ROOTNODE>"
+ "<TAG1 foo=\"goo\" id=\"tag1_id\">"
+ "Hello World"
+ "</TAG1>"
+ "</ROOTNODE>";
//instantiate the W3C DOM Parser
var parser = new DOMImplementation();
//load the XML into the parser and get the DOMDocument
var domDoc = parser.loadXML(xml);
//get the root node
var docRoot = domDoc.getDocumentElement();
//find tag1 by searching by its id
var tag1 = domDoc.getElementById("tag1_id");
//get a DOMNamedNodeMap of the attributes for tag1
var namedNodeMap = tag1.getAttributes();
//get the DOMAttr node with the name of "foo"
var fooNode = namedNodeMap.getNamedItem("foo");
//the following should be "true"
alert(fooNode.getSpecified());
}// end function xmljsDOMExample
DOMAttr - getOwnerElement method
W3C DOM Level 2
DOMAttr.getOwnerElement()
accepts:
N/A
returns:
DOMElement - The Element node the DOMAttr is attached to or null if it is not in use
throws:
N/A
The getOwnerElement method is a convenience method to access the DOMElement that
the DOMAttr is attached to. The following two statements are equivalent:
DOMAttr.getOwnerElement()
DOMAttr.getParentNode()
Example:
function xmljsDOMExample() {
var xml;
xml = ""
+ "<?xml version=\"1.0\"?>"
+ "<ROOTNODE>"
+ "<TAG1 foo=\"goo\" id=\"tag1_id\">"
+ "Hello World"
+ "</TAG1>"
+ "</ROOTNODE>";
//instantiate the W3C DOM Parser
var parser = new DOMImplementation();
//load the XML into the parser and get the DOMDocument
var domDoc = parser.loadXML(xml);
//get the root node
var docRoot = domDoc.getDocumentElement();
//find tag1 by searching by its id
var tag1 = domDoc.getElementById("tag1_id");
//get a DOMNamedNodeMap of the attributes for tag1
var namedNodeMap = tag1.getAttributes();
//get the DOMAttr node with the name of "foo"
var fooNode = namedNodeMap.getNamedItem("foo");
//the following should be "TAG1"
alert(fooNode.getOwnerElement().getNodeName());
//the following should be "true"
alert(tag1 == fooNode.getOwnerElement());
}// end function xmljsDOMExample
DOMAttr - getValue method
W3C DOM Level 1
DOMAttr.getValue()
accepts:
N/A
returns:
String - the value of the DOMAttr being queried
throws:
N/A
The getValue method returns the value of the queried DOMAttr object.
Example:
function xmljsDOMExample() {
var xml;
xml = ""
+ "<?xml version=\"1.0\"?>"
+ "<ROOTNODE>"
+ "<TAG1 foo=\"goo\" id=\"tag1_id\">"
+ "Hello World"
+ "</TAG1>"
+ "</ROOTNODE>";
//instantiate the W3C DOM Parser
var parser = new DOMImplementation();
//load the XML into the parser and get the DOMDocument
var domDoc = parser.loadXML(xml);
//get the root node
var docRoot = domDoc.getDocumentElement();
//find tag1 by searching by its id
var tag1 = domDoc.getElementById("tag1_id");
//get a DOMNamedNodeMap of the attributes for tag1
var namedNodeMap = tag1.getAttributes();
//get the DOMAttr node with the name of "foo"
var fooNode = namedNodeMap.getNamedItem("foo");
//the following should be "goo"
alert(fooNode.getValue());
}// end function xmljsDOMExample
DOMAttr - setValue method
W3C DOM Level 1
DOMAttr.setValue(<newValue>)
accepts:
String newValue - the new value for the DOMAttr node
returns:
N/A
throws:
The setValue method replaces the existing value of the DOMAttr node with the
value specified in newValue;
Example:
function xmljsDOMExample() {
var xml;
xml = ""
+ "<?xml version=\"1.0\"?>"
+ "<ROOTNODE>"
+ "<TAG1 foo=\"goo\" id=\"tag1_id\">"
+ "Hello World"
+ "</TAG1>"
+ "</ROOTNODE>";
//instantiate the W3C DOM Parser
var parser = new DOMImplementation();
//load the XML into the parser and get the DOMDocument
var domDoc = parser.loadXML(xml);
//get the root node
var docRoot = domDoc.getDocumentElement();
//find tag1 by searching by its id
var tag1 = domDoc.getElementById("tag1_id");
//get a DOMNamedNodeMap of the attributes for tag1
var namedNodeMap = tag1.getAttributes();
//get the DOMAttr node with the name of "foo"
var fooNode = namedNodeMap.getNamedItem("foo");
//set the foo attribute's value to "newFoo"
fooNode.setValue("newFoo");
//the following should be "newFoo"
alert(fooNode.getValue());
}// end function xmljsDOMExample