Skip to Content
Real World XML
book

Real World XML

by Steven Holzner
January 2003
Beginner to intermediate content levelBeginner to intermediate
1200 pages
23h 42m
English
Peachpit Press
Content preview from Real World XML

Getting Elements by Name

So far in this chapter, I've used navigation methods such as nextSibling and nextChild to move through XML documents. However, you can also get individual elements by searching for them by name. Here's an example. In this case, I'll use the document object's getElementsByTagName method to return a node list object holding all elements of a given name. In particular, I'm searching for <FIRST_NAME> and <LAST_NAME> elements, so I get lists of those elements like this:

<HTML> 
    <HEAD>
         <TITLE>
             Reading XML element values
         </TITLE>

         <SCRIPT LANGUAGE="JavaScript">
              function loadDocument()
              {
                  var xmldoc, listNodesFirstName, listNodesLastName

                  xmldoc = new ActiveXObject("Microsoft.XMLDOM")
                  xmldoc.load("ch07_01.xml")

                  listNodesFirstName ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Inside XML

Inside XML

Steven Holzner
XML Hacks

XML Hacks

Michael Fitzgerald

Publisher Resources

ISBN: 0735712867Purchase book