Net PerfectDev

Net PerfectDev

  • 1.6k
  • 146
  • 4.7k

Extract parent element from XML document

Oct 24 2020 7:10 PM
Hello, I have an xml document
  1. <Person Attribute1="Name" Attribute2="LastName" Attribute3="Age" Attribute4="Price">  
  2. <Person1 Attribute1Person1="NamePerson" Attribute2Person1="LastNamePerson" />  
  3. <Person2 Attribute1Person2="NamePerson" Attribute2Person2="LastNamePerson" />  
  4. <Person3 Attribute1Person3="NamePerson" Attribute2Person3="LastNamePerson" />  
  5. <Person4 Attribute1Person4="NamePerson" Attribute2Person4="LastNamePerson" />  
  6. </Person>  
  7. <Man Attribute1="Name" Attribute2="LastName" Attribute3="Age" Attribute4="Price">  
  8. <Man1 Attribute1Person1="NameMan" Attribute2Person1="LastNameMan" />  
  9. <Man2 Attribute1Person2="NameMan" Attribute2Person2="LastNameMan" />  
  10. <Man3 Attribute1Person3="NameMan" Attribute2Person3="LastNameMan" />  
  11. <Man4 Attribute1Person4="NameMan" Attribute2Person4="LastNameMan" />  
  12. </Man>  
  13. <Women Attribute1="Name" Attribute2="LastName" Attribute3="Age" Attribute4="Price">  
  14. <Women1 Attribute1Person1="NameWomen" Attribute2Person1="LastNameWomen" />  
  15. <Women2 Attribute1Person2="NameWomen" Attribute2Person2="LastNameWomen" />  
  16. <Women3 Attribute1Person3="NameWomen" Attribute2Person3="LastNameWomen" />  
  17. <Women4 Attribute1Person4="NameWomen" Attribute2Person4="LastNameWomen" />  
  18. </Women>  
I search how to extract this document with linq to have only the parent of each element.
  1. <Person Attribute1="Name" Attribute2="LastName" Attribute3="Age" Attribute4="Price">  
  2. <Man Attribute1="Name" Attribute2="LastName" Attribute3="Age" Attribute4="Price">  
  3. <Women Attribute1="Name" Attribute2="LastName" Attribute3="Age" Attribute4="Price">  

Answers (1)