Guest User

Untitled

a guest
Aug 3rd, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.43 KB | None | 0 0
  1. Parsing data using XDocument yield no result -Why?
  2. <!--Sample Person Data-->
  3. <Person>
  4. <PersonDetail PersonId="1">
  5. <Name>Priyanka Das</Name>
  6. <Age>30</Age>
  7. <Sex>Male</Sex>
  8. <LivesIn>Bangalore</LivesIn>
  9. <Email>nb@training.com</Email>
  10. </PersonDetail>
  11. <PersonDetail PersonId="2">
  12. <Name>Shashidhar Nikatani</Name>
  13. <Age>40</Age>
  14. <Sex>Male</Sex>
  15. <LivesIn>Bangalore</LivesIn>
  16. <Email>sn@training.com</Email>
  17. </PersonDetail>
  18. <PersonDetail PersonId="3">
  19. <Name>Arundhuti Roy</Name>
  20. <Age>27</Age>
  21. <Sex>Female</Sex>
  22. <LivesIn>Kerala</LivesIn>
  23. <Email>ab@training.com</Email>
  24. </PersonDetail>
  25. <PersonDetail PersonId="4">
  26. <Name>Nitin Mallik</Name>
  27. <Age>28</Age>
  28. <Sex>Male</Sex>
  29. <LivesIn>Bangalore</LivesIn>
  30. <Email>ng@training.com</Email>
  31. </PersonDetail>
  32. <PersonDetail PersonId="5">
  33. <Name>Essaki Raja Kandaswamy</Name>
  34. <Age>27</Age>
  35. <Sex>Male</Sex>
  36. <LivesIn>Madras</LivesIn>
  37. <Email>er@training.com</Email>
  38. </PersonDetail>
  39. </Person>
  40.  
  41. XDocument xmlSource = null;
  42. xmlSource = XDocument.Load(@"D:Personsample.xml");
  43.  
  44. var query = from data in xmlSource.Descendants("Person")
  45. where (string)data.Element("LivesIn") == "Bangalore"
  46. select data;
  47.  
  48. from data in xmlSource.Descendants("PersonDetail")
  49. where (string)data.Element("LivesIn") == "Bangalore"
  50. select data;
Add Comment
Please, Sign In to add comment