Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,038

HOME > Mobile > Mobile Forum > How to get xml nested element values in windwos phone?


[Mobile] How to get xml nested element values in windwos phone?

 
Topic : 098656

Guest



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)
01.<Categories>
02.<Category title="curtains" categoryid="1" image="http://123k.com/images/uploads/C/1360922323.png" totalsubcategories="8">
03.<SubCategory>
04. 
05.<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>
06. 
07.</Category>
08. 
09.</Categories>

Code (C#)
01.XDocument xmlDoc = XDocument.Parse(dataInXmlFile);
02.                
03.               var query = from l in xmlDoc.Descendants("Category")
04.                           select new Class
05.                           {
06.                               Titles = l.Attribute("title").Value,
07.                               Images = l.Attribute("image").Value,
08.                               ProductCount = l.Attribute("totalsubcategories").Value,
09.                               Articles = l.Element("SubCategory").Elements("Subcategory")
10.                                                 .Select(article => new Subclass
11.                                                 {
12.                                                     name = article.Attribute("name").Value,
13.                                                     Subimage = article.Attribute("subimage").Value,
14.                                                     Product = article.Element("Products").Elements("product")
15.                                                                    .Select(articles => new Product
16.                                                                    {
17.                                                                        Price = articles.Element("productprice").Value,
18.                                                                        
19.                                                                        Producttype = articles.Element("Retailers").Elements("Retailerslist")
20.                                                                                      .Select(retails => new Retailers
21.                                                                                       {
22.                                                                                           retailer = retails.Element("Retailername").Value,
23. 
24.                                                                                       }).ToList(),
25.                                                                        ProductId = articles.Attribute("id").Value,
26.                                                                        ProductName = articles.Attribute("name").Value,
27.                                                                        ProductImage = articles.Element("productimage").Value,
28.                                                                        Shortdescription = articles.Element("productshortdescription").Value
29.                                                                    }).ToList(),
30. 
31.                                                 })
32.                                                 .ToList(),
33. 
34.                           };

Code (C#)
01.[XmlRoot("root")]
02.    public class Array
03.    {
04.        [XmlArray("Categories")]
05.        [XmlArrayItem("Category")]
06.        [XmlArrayItem("SubCategory")]
07.        [XmlArrayItem("Subcategory")]
08.        [XmlArrayItem("Product")]
09.        [XmlArrayItem("product")]
10.        [XmlArrayItem("Retailers")]
11. 
12.        public ObservableCollection<Class> Collection { get; set; }
13.    }

Code (C#)
01.public class Class
02.    {
03.        public List<SubClass> Articles { get; set; }
04. 
05.       // public string ProductCount { get; set; }
06. 
07.        public string CategoryId { get; set; }
08. 
09.        [XmlAttribute("title")]
10.        public string Titles { get; set; }
11. 
12.        [XmlAttribute("image")]
13.        public string Images { get; set; }
14. 
15.        public string name { get; set; }
16. 
17.        public string Subimage { get; set; }
18. 
19.        public string SubcategoryId { get; set; }
20. 
21.        public string ProductName { get; set; }
22. 
23.        public string ProductCount { get; set; }
24.    }
25. 
26.public class SubClass
27.    {
28.        public string name { get; set; }
29. 
30.        public string Subimage { get; set; }
31. 
32.        public string SubcategoryId { get; set; }
33. 
34.        public string ProductName { get; set; }
35. 
36.        public string Producttype { get; set; }
37. 
38.        public string ProductCount { get; set; }
39. 
40.        public string Retailerslist { get; set; }
41. 
42.        public List<Product> Product { get; set; }
43. 
44.    }
45. 
46.public class Product
47.    {
48.        public List<Retailers> Producttype { get; set; }
49. 
50.        public string ProductName { get; set; }
51. 
52.        public string ProductImage { get; set; }
53. 
54.        public string Shortdescription { get; set; }
55. 
56.        public string Price { get; set; }
57. 
58.        public string ProductId { get; set; }
59.    }
60. 
61.public class Retailers
62.    {
63.        public string retailer { get; set; }
64.    }


I tried this code i got null reference value



Tag : Mobile, MySQL, Device (Mobile), C#, Windows Phone, Windows

Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-08-03 18:35:53 By : Get xml nested element value View : 1094 Reply : 1
 

 

No. 1



โพสกระทู้ ( 74,059 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Windows Phone and XML Parser

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-08-07 05:56:54 By : mr.win
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : How to get xml nested element values in windwos phone?
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)





ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2025 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่