I tried to query product name and product image out of my xml file "favorite.xml" at the start of application, and put it all in the list of favorite product. My query statement is like this
private void Favorite_Load()
{
var storage = IsolatedStorageFile.GetUserStoreForApplication();
fileName = "Favorite\\favorite.xml";
using (IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream(fileName, FileMode.Open, storage))
{
lst_product1.Items.Clear();
XDocument doc = XDocument.Load(isoStream);
//Check if there is favorite element in the favorite.xml file
if (doc.Root.Descendants("favorite").Count() > 0)
{
var data = from query in doc.Descendants("favorite")
orderby query.Attribute("id").Value
select new ProductsDry
{
favID = query.Attribute("id").Value,
favProCate = query.Attribute("cate_xml").Value,
favProId = query.Attribute("pro_id").Value,
favProImage = query.Attribute("pro_image").Value,
favProName = query.Attribute("pro_name").Value
};
lst_product1.ItemsSource = data; // data=null
}
isoStream.Position = 0;
isoStream.Dispose();
}
}
Here's my "favorite.xml" file
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<!--Favorite's xml-->
<favorites>
<favorite id="1" pro_id="1" pro_name="Boots Expert Anti-Blemish Cleansing Foam" cate_xml="ProductsOily.xml" pro_image="images/Oily-Dry/BO001.JPG" />
<favorite id="2" pro_id="3" pro_name="Cerave foaming facial cleanser" cate_xml="ProductsOily.xml" pro_image="images/Oily-Dry/CV001.JPG" />
<favorite id="3" pro_id="9" pro_name="L'Oreal Paris Go 360 Clean Anti-Breakout Facial Cleanser" cate_xml="ProductsOily.xml" pro_image="images/Oily-Dry/LO003.JPG" />
<favorite id="4" pro_id="10" pro_name="Olay Foaming Face Wash - Sensitive" cate_xml="ProductsOily.xml" pro_image="images/Oily-Dry/OL014.JPG" />
<favorite id="5" pro_id="22" pro_name="Alpha Hydrox Sheer Silk Moisturizer SPF 15 Sunscreen " cate_xml="ProductsOily.xml" pro_image="images/Oily-Dry/bp256.1.jpg" />
</favorites>
However, after all it doesn't show anything in the list, instead it shows something like the path of the project, and my query is null as I debug it.
Before, I always use this code to read data and show it from xml file but the xml file is not located in Isoloated Storage. I know this time I read it from Isoloated Storage; therefore, there must be something different. Please help, thanks.
No comments:
Post a Comment