The University of Chicago Booth School of Business 36104 Class Exercise: XML and the Document Object Model Part 1: Get a String with the XML Data 1. Open an empty workbook. 2. Download and import the SQL Web Service class clsSqlService into your workbook. 3. Create module and in a procedure Dim up a string Dim xmlResult As String 3. Select all of the records in the doowop database and put the result in the string xmlResult. Here is the XML that is in xmlResult: See kipp.chicagobooth.edu/xml/dooWopQuery.xml. Part 2: Create the XML Objects 1. Create a new DOM object Dim dooWopDom As DOMDocument60 Set dooWopDom = New DOMDocument60 2. Populate the new object dooWopDom.LoadXML (xmlResult) 3. Dim up and define the root element object Dim root As IXMLDOMNode Set root = dooWopDom.DocumentElement KEY QUESTIONS: Look at the XML that is in xmlResult: See kipp.chicagobooth.edu/xml/dooWopQuery.xml. 1. What does the root object correspond to? 2. What would be the result of Debug.Print root.baseName? 1 Part 3: Looping Over Children 1. Dim up an object childNode in the IXMLDOMNode class. 2. Create a For Each loop. Loop over each childNode in the ChildNodes set of the root element and print their BaseName. 3. Modify the code so you only print the name if the name is record. KEY QUESTION: 1. What are the objects in ChildNodes Part 4: Obtain Specific Element Information KEY QUESTIONS: 1. Each childNode in the loop has children. What are the children? 2. In VBA, the children of childNode are in the set of objects childNode.ChildNodes. You can access child k by the call childNode.ChildNodes.Item(k) What would childNode.ChildNodes.Item(0) return? What about childNode.ChildNodes.Item(1)? What about childNode.ChildNodes.Item(1).Text? Part 5: Put Information Into An Array 1. Dim up title() as a string array() 2. Each childNode object in the loop has children. For each child of a record object, get the song title and put it in the array title() if the year that the song was released was 1960 or earlier. 2 3
© Copyright 2026 Paperzz