Chapter 18. Working with Data

In Lesson 15 you learned how to consume XML from a web service and bind it to elements in your application. If you want the user to be able to use your application when networking is not available, such as when the user is on an airplane, you will want to provide a means of populating the data from a local data file.

READING FROM AN XML FILE

You could have your application pull down a copy of the most current version of the data file when the user is connected to the Internet and store the data as an XML file in the program's isolated storage. This will serve as the source of data when an Internet connection is unavailable. You could include a base version of the XML file with your application for use until the XML file is updated.

Adding the XML File

If you are building an e-commerce application and want to include a default set of products with the application, you can include an XML file such as the following:

<JHProducts> <Product> <ProductID>7000</ProductID> <ProductCode>EV100-11</ProductCode> <ProductType>Anniversary</ProductType> <ProductIntroductionDate>All Year </ProductIntroductionDate> <ProductName>The Perfect Dozen</ProductName> <ProductDescription>A dozen red roses are always perfect, always savored. We add even more charming beauty with seeded eucalyptus and spiral eucalyptus. Item number EV 100-11.</ProductDescription> <ProductImageURL>EV100-11.jpg</ProductImageURL> <ProductImageURLlarge>EV100-11.jpg</ProductImageURLlarge> <UnitPrice>$60.00</UnitPrice> ...

Get Windows® Phone 7 Application Development 24-Hour Trainer now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.