<?xml version="1.0"?

A Windows Forms application reads the following XML file.

<?xml version=”1.0″?>
<x:catalog xmlns:x=”urn:books”>
<book id=”bk101″>
<author>Gambardella, Matthew</author>
<title>XML Developer’s Guide</title>
</book>
<book id=”bk102″>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
</book>
</x:catalog>

The form initialization loads this file into an XmlDocument object named docBooks. You need to populate a ListBox control named lstBooks with the concatenated book ID and title of each book. Which code segment should you use?

A Windows Forms application reads the following XML file.

<?xml version=”1.0″?>
<x:catalog xmlns:x=”urn:books”>
<book id=”bk101″>
<author>Gambardella, Matthew</author>
<title>XML Developer’s Guide</title>
</book>
<book id=”bk102″>
<author>Ralls, Kim</author>
<title>Midnight Rain</title>
</book>
</x:catalog>

The form initialization loads this file into an XmlDocument object named docBooks. You need to populate 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 As XmlElementFor Each node In elements Dim s As String = node.GetAttribute(“id”) + ” – ” s = s + node.SelectSingleNode(“title”).InnerText lstBooks.Items.Add(s)Next node

B.
Dim elements As XmlNodeList = docBooks.GetElementsByTagName(“book”)Dim node As XmlElementFor Each node In elements Dim s As String = node.SelectSingleNode(“id”).ToString() + ” – ” s = s + node.GetAttribute(“title”) lstBooks.Items.Add(s)Next node

C.
Dim elements As XmlNodeList = docBooks.GetElementsByTagName(“book”)Dim node As XmlElementFor Each node In elements Dim s As String = node.GetAttribute(“id”) + ” – ” s = s + node.SelectSingleNode(“title”).Value lstBooks.Items.Add(s)Next node

D.
Dim elements As XmlNodeList = docBooks.GetElementsByTagName(“book”)Dim node As XmlElementFor Each node In elements lstBooks.Items.Add(node.InnerXml)Next node



Leave a Reply 0

Your email address will not be published. Required fields are marked *