http://www./dom/dom_attribute.aspXML DOM Get Nodes![]() ![]() ExamplesIn the examples below, we will use the XML file books.xml, and the JavaScript function loadXMLDoc(). Get an element‘s value Get an attribute‘s value Get an item‘s value Get an Element‘s ValueThe getElementsByTagname() method returns a nodelist that contains all elements with the specified tag name in the same order as they appear in the source document. The following code fragment prints the values of all "title" elements in "books.xml":
Output:
Get an Attribute‘s ValueThe getAttribute() method can be used to display the value of an attribute. The following code fragment prints the values of all "category" attributes in "books.xml":
Output:
Get an Item‘s ValueThe getNamedItem() method can be used to retrieve a specified node. The following code fragment shows how to print the value of the "category" attribute in each <book> element":
Output:
![]() ![]() |
|