PrepAway - Latest Free Exam Questions & Answers

Which code segment should you insert at line 07?

You create an application by using the Microsoft .NET Framework 3.5 and Microsoft
ADO.NET.You write the following code segment. (Line numbers are included for reference
only.)
01 private List<string> GetEmployers() {
02 List<string> employers = new List<string>();
03 SqlCommand cmd = new SqlCommand();
04 …
05 XmlReader reader = cmd.ExecuteXmlReader();
06 while (reader.Read()) {
07
08 }
09 return employers;
10 }
The cmd object returns the following XML data structure.
<Resume>
<Name>
<Name.First>Shai</Name.First>
<Name.Last>Bassli</Name.Last>
</Name>
<Employment>
<Emp.OrgName>Wingtip Toys</Emp.OrgName>

</Employment>

</Resume>
You need to populate the employers list with each employer entry in the XML data
structure.
Which code segment should you insert at line 07?

PrepAway - Latest Free Exam Questions & Answers

A.
if (reader.Name == “Emp.OrgName”) {
string employer = reader.ReadElementContentAsString();
employers.Add(employer);
}

B.
if (reader.Name == “Emp.OrgName”) {
reader.MoveToContent();
string employer = reader.Value;
employers.Add(employer);
}

C.
if (reader.Name == “Emp.OrgName” && reader.HasAttributes) {
reader.MoveToFirstAttribute(); string employer = reader.Value; employers.Add(employer);
}

D.
if (reader.Name == “Emp.OrgName”) {
reader.MoveToFirstAttribute();
if (reader.HasValue) {
string employer = reader.Value;
employers.Add(employer);
}
}


Leave a Reply