Answer(s)
- Windows Forms application reads the following XML file.Gambardella, MatthewXML Developer's GuideRalls, KimMidnight RainThe form initialization loads this file into an XmlDocument object named docBooks. You need topopulate a ListBox control named lstBooks with the concatenated book ID and title of each book.Which code segment should you use?A. Dim elements As XmlNodeList = docBooks.GetElementsByTagName("book")Dim node AsXmlElementFor Each node In elements Dim s As String = node.GetAttribute("id") + " - " s = s +node.SelectSingleNode("title").InnerText lstBooks.Items.Add(s)Next node
- Dim elements As XmlNodeList = docBooks.GetElementsByTagName("book")Dim node AsXmlElementFor Each node In elements Dim s As String = node.SelectSingleNode("id").ToString()+ " - " s =s + node.GetAttribute("title") lstBooks.Items.Add(s)Next node
- Dim elements As XmlNodeList = docBooks.GetElementsByTagName("book")Dim node AsXmlElementFor Each node In elements Dim s As String = node.GetAttribute("id") + " - " s = s +node.SelectSingleNode("title").Value lstBooks.Items.Add(s)Next node
- Dim elements As XmlNodeList = docBooks.GetElementsByTagName("book")Dim node AsXmlElementFor Each node In elements lstBooks.Items.Add(node.InnerXml)Next node
Correct Answer
Windows Forms application reads the following XML file.Gambardella, MatthewXML Developer's GuideRalls, KimMidnight RainThe form initialization loads this file into an XmlDocument object named docBooks. You need topopulate a ListBox control named lstBooks with the concatenated book ID and title of each book.Which code segment should you use?A. Dim elements As XmlNodeList = docBooks.GetElementsByTagName("book")Dim node AsXmlElementFor Each node In elements Dim s As String = node.GetAttribute("id") + " - " s = s +node.SelectSingleNode("title").InnerText lstBooks.Items.Add(s)Next node