|
|
|
How to get xml nested element values in windwos phone? |
|
|
|
|
|
|
|
Hi i need get xml nested element values.i tried some code but i got null reference. so help me how to do this am using my code given below.
Code (XML)
<Categories>
<Category title="curtains" categoryid="1" image="http://123k.com/images/uploads/C/1360922323.png" totalsubcategories="8">
<SubCategory>
<Subcategory name="Childrens Curtains" subcategoryid="3" subimage="http://123.com/images/uploads/S/1364015644.jpg" totalProducts="1"> <Products> <product name="Vintage Pink Pencil Pleat Curtain" id="6"> <Retailers> <Retailername>Curtains and Curtains</Retailername> <Retailername>Amazing Curtains MM</Retailername> </Retailers> <productimage> http://123.com/images/uploads/P/1361354113.jpg </productimage> <productshortdescription> Vintage Pink Pencil Pleat Curtain'Complete the Look'. </productshortdescription> <productprice>13.00</productprice> </product> </Products> </Subcategory>
</Category>
</Categories>
Code (C#)
XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
var query = from l in xmlDoc.Descendants("Category")
select new Class
{
Titles = l.Attribute("title").Value,
Images = l.Attribute("image").Value,
ProductCount = l.Attribute("totalsubcategories").Value,
Articles = l.Element("SubCategory").Elements("Subcategory")
.Select(article => new Subclass
{
name = article.Attribute("name").Value,
Subimage = article.Attribute("subimage").Value,
Product = article.Element("Products").Elements("product")
.Select(articles => new Product
{
Price = articles.Element("productprice").Value,
Producttype = articles.Element("Retailers").Elements("Retailerslist")
.Select(retails => new Retailers
{
retailer = retails.Element("Retailername").Value,
}).ToList(),
ProductId = articles.Attribute("id").Value,
ProductName = articles.Attribute("name").Value,
ProductImage = articles.Element("productimage").Value,
Shortdescription = articles.Element("productshortdescription").Value
}).ToList(),
})
.ToList(),
};
Code (C#)
[XmlRoot("root")]
public class Array
{
[XmlArray("Categories")]
[XmlArrayItem("Category")]
[XmlArrayItem("SubCategory")]
[XmlArrayItem("Subcategory")]
[XmlArrayItem("Product")]
[XmlArrayItem("product")]
[XmlArrayItem("Retailers")]
public ObservableCollection<Class> Collection { get; set; }
}
Code (C#)
public class Class
{
public List<SubClass> Articles { get; set; }
// public string ProductCount { get; set; }
public string CategoryId { get; set; }
[XmlAttribute("title")]
public string Titles { get; set; }
[XmlAttribute("image")]
public string Images { get; set; }
public string name { get; set; }
public string Subimage { get; set; }
public string SubcategoryId { get; set; }
public string ProductName { get; set; }
public string ProductCount { get; set; }
}
public class SubClass
{
public string name { get; set; }
public string Subimage { get; set; }
public string SubcategoryId { get; set; }
public string ProductName { get; set; }
public string Producttype { get; set; }
public string ProductCount { get; set; }
public string Retailerslist { get; set; }
public List<Product> Product { get; set; }
}
public class Product
{
public List<Retailers> Producttype { get; set; }
public string ProductName { get; set; }
public string ProductImage { get; set; }
public string Shortdescription { get; set; }
public string Price { get; set; }
public string ProductId { get; set; }
}
public class Retailers
{
public string retailer { get; set; }
}
I tried this code i got null reference value
Tag : Mobile, MySQL, Device (Mobile), C#, Windows Phone, Windows
|
|
|
|
|
|
Date :
2013-08-03 18:35:53 |
By :
Get xml nested element value |
View :
1059 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Windows Phone and XML Parser
|
|
|
|
|
Date :
2013-08-07 05:56:54 |
By :
mr.win |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 01
|