03.01.2015 Views

C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

Visual Studio 2013 C# 5.0 Programmer's Reference

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Exercises ❘ 561<br />

3. Write a program similar to the one shown in Figure 24-6 to display the plant data generated<br />

by the program you wrote for Exercise 1 or 2.<br />

Figure 24-6: For Exercise 3, write a<br />

program that displays the plant data<br />

you generated in Exercises 1 and 2.<br />

When it starts, the program should load the plant XML file into a DOM. It should use the<br />

XDocument object’s Descendants method to find Zone elements and use LINQ and to display<br />

a sorted list of the distinct Zone values in the form’s ComboBox.<br />

When the user selects a zone, the program should display the names of the plants in that zone<br />

in the Plants ListBox. (Hints: Use the Descendants method to find Zone elements. Use LINQ<br />

to select the elements with the selected zone. Loop through the selected elements. Use each element’s<br />

Parent property to get to its Plant element. Then use the parent’s Element method to<br />

get the Name subelement.)<br />

When the user clicks a plant in the Plants ListBox, display the information about that<br />

plant. (Hints: Use Descendants again to find Name elements and use LINQ to select the<br />

one with the selected name. Get the first selected element’s parent and call the parent’s<br />

ToString method.)<br />

4. Write a program that reads the plant data generated by the program you wrote for Exercise 1<br />

or 2 and displays a list of the plant records’ names. (Hints: Scan the file to find Name elements.<br />

With those elements, use the reader’s ReadElementContentAsString or ReadInnerXml<br />

method to get the element’s content.)<br />

Compare this program with the one you wrote for Exercise 3. Under what circumstances is<br />

one better than the other<br />

5. Modify the program you wrote for Exercise 3 so that it uses XPath instead of LINQ to find<br />

the elements it needs.<br />

6. Modify the TransformPlanets example program so that it transforms the Plants.xml file created<br />

by the program you wrote for Exercise 1 or Exercise 2 and displays it in an HTML page.<br />

www.it-ebooks.info

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!