Question 2) TS: Microsoft .NET Framework 2.0
Objective: Integrating Data in a Web Application by Using ADO.NET, XML, and Data-Bound Controls
SubObjective: Manage XML Data with the XML Document Object Model (DOM)
Single Answer Multiple Choice
You are reviewing an ASP.NET application developed by another developer. The ASP.NET applications contain the following code to read the employee.xml file:
Dim myXMLDoc As XmlDocument
myXMLDoc.Load(“employee.xml”)
Dim ReadChild As XmlNode = _
myXMLDoc.SelectSingleNode(“/Employees/Employee/Name”)
Dim ReadNode As New XmlNodeReader(ReadChild)
While ReadNode.Read()
Response.Write(ReadNode.Value)
End While
The employee.xml file contains the following XML:
<?xml version=”1.0″ encoding=”utf-8″?>
<Employees>
<Employee>
<EmpId>E001</EmpId>
<Name>Tom</Name>
</Employee>
<Employee>
<EmpId>E002</EmpId>
<Name>Peter</Name>
</Employee>
</Employees>
When the ASP.NET application is executed, which value is displayed on the Web page?
A. The following value is displayed:
Tom
B. The following value is displayed:
E001Tom
C. The following value is displayed:
E001Tom E002Peter
D. The following value is displayed:
Tom Peter
Answer:
A. The following value is displayed:
Tom
Tutorial:
The following value will be displayed on the Web page:
Tom
In this scenario, the code uses the ReadNode object of the XMLNodeReader class. The ReadNode object is used to read values of specific nodes in a subtree. The code creates an object named myXMLdoc of the XmlDocument class to store the XML document. The employee.xml file is specified as an argument of the Load method of the myXMLdoc object. The code initializes a ReadChild method of the XmlNode class to position the reader at the first Employee node in the employee.xml file. To read the values of the specified node named Name, the code creates a ReadNode object of the XMLNodeReader class and specifies the ReadChild object as an argument of the constructor. To read the values stored in the ReadNode object, the code calls the Read method of the ReadNode object.
All the other options are incorrect because the XMLNodeReader class reads the values in the node on which the reader is currently positioned. In this scenario, the reader is positioned at the first Name node of the first Employee element.
These questions are derived from the Self Test Software Practice Test for Microsoft exam #70-528 – TS: Microsoft .NET Framework 2.0 – Web-Based Client Development (VB.NET)