PrepAway - Latest Free Exam Questions & Answers

Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code?

DRAG DROP
You are developing a C# application. The application includes a class named Rate. The following code
segment implements the Rate class:

You define a collection of rates named rateCollection by using the following code segment:
Collection<Rate> rateCollection = new Collection<Rate>() ;
The application receives an XML file that contains rate information in the following format:

You need to parse the XML file and populate the rateCollection collection with Rate objects.
You have the following code:

Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete
the code? (To answer, drag the appropriate code segments to the correct targets in the answer are
a. Each code segment may be used once, more than once, or not at all. You may need to drag the
split bar between panes or scroll to view content.)

PrepAway - Latest Free Exam Questions & Answers

Answer:

Explanation:

* Target 1: The element name is rate not Ratesheet.
The Xmlreader readToFollowing reads until the named element is found.
* Target 2:
The following example gets the value of the first attribute.
reader.ReadToFollowing(“book”);
reader.MoveToFirstAttribute();
string genre = reader.Value;
Console.WriteLine(“The genre value: ” + genre);
* Target 3, Target 4:
The following example displays all attributes on the current node.
C#VB
if (reader.HasAttributes) {
Console.WriteLine(“Attributes of <” + reader.Name + “>”);
while (reader.MoveToNextAttribute()) {
Console.WriteLine(” {0}={1}”, reader.Name, reader.Value);
}
// Move the reader back to the element node.
reader.MoveToElement();
}
The XmlReader.MoveToElement method moves to the element that contains the current attribute
node.

XmlReader Methods
https://msdn.microsoft.com/en-us/library/System.Xml.XmlReader_methods(v=vs.110).aspx

3 Comments on “Which code segments should you include in Target 1, Target 2, Target 3 and Target 4 to complete the code?

  1. Hans Werner says:

    Target 4 should be ReadToFollowing(“value”)

    Example for verification:

    StringReader sr = new StringReader(
    @”

    0.0375

    0.0475

    “);
    using (XmlReader reader = XmlReader.Create(sr))
    {
    while (reader.ReadToFollowing(“rate”))
    {
    Console.WriteLine(“In element ‘” + reader.Name + “‘”);

    reader.MoveToFirstAttribute();
    Console.WriteLine(“First attribute ‘” + reader.Name + “‘: ” + reader.Value);

    reader.MoveToNextAttribute();
    Console.WriteLine(“Next attribute ‘” + reader.Name + “‘: ” + reader.Value);

    reader.ReadToFollowing(“value”);
    Console.WriteLine(“In element ‘” + reader.Name + “‘”);
    Console.WriteLine(“Content: ” + reader.ReadElementContentAsDecimal());
    }
    }




    1



    0

Leave a Reply