Programmer's Guide > Programming and Scripting Techniques > Basic Document Manipulation Using the DOM and AOM > Traversing a Document Using the DOM and AOM > Using getElementsByTagName
  
Using getElementsByTagName
In this example, the tree is traversed by calling getElementsByTagName. All of the Document, ADocument, Element, and AElement interface getElementsByXxx methods populate a NodeList with nodes in the order encountered in a preorder traversal of the tree. All occurrences of the <emphasis> tag have their role attribute value changed from bold to italic, changing all bold text to italic. This is done by iterating over the NodeList returned by getElementsByTagName, and using Node.getAttribute to check the value of each node's role attribute, and then using Node.setAttribute to change that value to italic.
var doc = Application.activeDocument;
//get all emphasis tags in the document
var tags = doc.getElementsByTagName("emphasis");
for(i=0; i < tags.length; i++) {
if(tags.item(i).getAttribute("role") == "bold") {
tags.item(i).setAttribute("role", "italic")
}
}